Initial commit to Gerrit
[profile/ivi/orc.git] / testsuite / compile_parse_neon.c
1
2 #include <orc/orc.h>
3 #include <orc-test/orctest.h>
4 #include <orc/orcparse.h>
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 static char * read_file (const char *filename);
10 void output_code (OrcProgram *p, FILE *output);
11 void output_code_header (OrcProgram *p, FILE *output);
12 void output_code_test (OrcProgram *p, FILE *output);
13
14 int error = FALSE;
15
16 int
17 main (int argc, char *argv[])
18 {
19   char *code;
20   int n;
21   int i;
22   OrcProgram **programs;
23   const char *filename = NULL;
24
25   orc_init ();
26   orc_test_init ();
27
28   if (argc >= 2) {
29     filename = argv[1];
30   }
31   if (filename == NULL) {
32     filename = getenv ("testfile");
33   }
34   if (filename == NULL) {
35     filename = "test.orc";
36   }
37   code = read_file (filename);
38   if (!code) {
39     printf("compile_parse_test <file.orc>\n");
40     exit(1);
41   }
42
43   n = orc_parse (code, &programs);
44
45   for(i=0;i<n;i++){
46     OrcTestResult ret;
47
48     printf("%s:\n", programs[i]->name);
49     ret = orc_test_gcc_compile_neon (programs[i]);
50     if (ret == ORC_TEST_FAILED) {
51       error = TRUE;
52     }
53   }
54
55   if (error) return 1;
56   return 0;
57 }
58
59
60 static char *
61 read_file (const char *filename)
62 {
63   FILE *file = NULL;
64   char *contents = NULL;
65   long size;
66   int ret;
67
68   file = fopen (filename, "r");
69   if (file == NULL) return NULL;
70
71   ret = fseek (file, 0, SEEK_END);
72   if (ret < 0) goto bail;
73
74   size = ftell (file);
75   if (size < 0) goto bail;
76
77   ret = fseek (file, 0, SEEK_SET);
78   if (ret < 0) goto bail;
79
80   contents = malloc (size + 1);
81   if (contents == NULL) goto bail;
82
83   ret = fread (contents, size, 1, file);
84   if (ret < 0) goto bail;
85
86   contents[size] = 0;
87
88   return contents;
89 bail:
90   /* something failed */
91   if (file) fclose (file);
92   if (contents) free (contents);
93
94   return NULL;
95 }
96