Home | History | Annotate | Download | only in crosstest
      1 //===- subzero/crosstest/test_global_main.cpp - Driver for tests ----------===//
      2 //
      3 //                        The Subzero Code Generator
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // Driver for crosstesting global variable access operations.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 /* crosstest.py --test=test_global.cpp \
     15    --driver=test_global_main.cpp --prefix=Subzero_ --output=test_global */
     16 
     17 #include <stdint.h>
     18 #include <cstdlib>
     19 #include <iostream>
     20 
     21 #include "test_global.h"
     22 namespace Subzero_ {
     23 #include "test_global.h"
     24 }
     25 
     26 int ExternName1 = 36363;
     27 float ExternName2 = 357.05e-10;
     28 char ExternName3[] = {'a', 'b', 'c'};
     29 struct Data {
     30   int a;
     31   float b;
     32   double d;
     33 };
     34 
     35 struct Data SimpleData = {-111, 2.69, 55.19};
     36 
     37 struct Data *ExternName4 = &SimpleData;
     38 
     39 double ExternName5 = 3.44e26;
     40 
     41 int main(int argc, char **argv) {
     42   // Prevent pnacl-opt from deleting "unused" globals.
     43   if (argc < 0) {
     44     std::cout << &ExternName1 << &ExternName2 << &ExternName3 << &SimpleData
     45               << &ExternName4 << ExternName5;
     46   }
     47   size_t TotalTests = 0;
     48   size_t Passes = 0;
     49   size_t Failures = 0;
     50 
     51   const uint8_t *SzArray, *LlcArray;
     52   size_t SzArrayLen, LlcArrayLen;
     53 
     54   size_t NumArrays = getNumArrays();
     55   for (size_t i = 0; i < NumArrays; ++i) {
     56     LlcArrayLen = -1;
     57     SzArrayLen = -2;
     58     LlcArray = getArray(i, LlcArrayLen);
     59     SzArray = Subzero_::getArray(i, SzArrayLen);
     60     ++TotalTests;
     61     if (LlcArrayLen == SzArrayLen) {
     62       ++Passes;
     63     } else {
     64       std::cout << i << ":LlcArrayLen=" << LlcArrayLen
     65                 << ", SzArrayLen=" << SzArrayLen << "\n";
     66       ++Failures;
     67     }
     68 
     69     for (size_t i = 0; i < LlcArrayLen; ++i) {
     70       ++TotalTests;
     71       if (LlcArray[i] == SzArray[i]) {
     72         ++Passes;
     73       } else {
     74         ++Failures;
     75         std::cout << i << ":LlcArray[" << i << "] = " << (int)LlcArray[i]
     76                   << ", SzArray[" << i << "] = " << (int)SzArray[i] << "\n";
     77       }
     78     }
     79   }
     80 
     81   std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
     82             << " Failures=" << Failures << "\n";
     83   return Failures;
     84 }
     85