tests: Add compile_parse
authorDavid Schleef <ds@schleef.org>
Mon, 7 Jun 2010 18:42:07 +0000 (11:42 -0700)
committerDavid Schleef <ds@schleef.org>
Mon, 7 Jun 2010 21:41:00 +0000 (14:41 -0700)
testsuite/Makefile.am
testsuite/compile_parse.c [new file with mode: 0644]

index 9936b47..8eac198 100644 (file)
@@ -17,7 +17,7 @@ XFAIL_TESTS = \
        exec_opcodes_float
 
 noinst_PROGRAMS = $(TESTS) generate_xml_table generate_xml_table2 \
-       generate_opcodes_sys compile_parse_c memcpy_speed \
+       generate_opcodes_sys compile_parse compile_parse_c memcpy_speed \
        exec_parse \
        compile_opcodes_sys_c \
        compile_opcodes_float_c \
@@ -34,8 +34,8 @@ noinst_PROGRAMS += compile_opcodes_sys_neon \
        compile_opcodes_float_neon \
        compile_parse_neon
 
-AM_CFLAGS = $(ORC_CFLAGS)
-LIBS = $(ORC_LIBS) $(top_builddir)/orc-test/liborc-test-@ORC_MAJORMINOR@.la
+AM_CFLAGS = $(ORC_CFLAGS) -I/usr/local/include/liboil-0.3/
+LIBS = $(ORC_LIBS) $(top_builddir)/orc-test/liborc-test-@ORC_MAJORMINOR@.la -loil-0.3
 
 compile_opcodes_float_c_LDADD = \
        $(top_builddir)/orc-float/liborc-float-@ORC_MAJORMINOR@.la
diff --git a/testsuite/compile_parse.c b/testsuite/compile_parse.c
new file mode 100644 (file)
index 0000000..a950fdc
--- /dev/null
@@ -0,0 +1,90 @@
+
+#include <orc/orc.h>
+#include <orc-test/orctest.h>
+#include <orc/orcparse.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static char * read_file (const char *filename);
+void output_code (OrcProgram *p, FILE *output);
+void output_code_header (OrcProgram *p, FILE *output);
+void output_code_test (OrcProgram *p, FILE *output);
+
+int error = FALSE;
+
+int
+main (int argc, char *argv[])
+{
+  char *code;
+  int n;
+  int i;
+  OrcProgram **programs;
+  const char *filename = "test.orc";
+
+  orc_init ();
+  orc_test_init ();
+
+  if (argc >= 2) {
+    filename = argv[1];
+  }
+  code = read_file (filename);
+  if (!code) {
+    printf("compile_parse_test <file.orc>\n");
+    exit(1);
+  }
+
+  n = orc_parse (code, &programs);
+
+  for(i=0;i<n;i++){
+    OrcCompileResult ret;
+
+    printf("%s:\n", programs[i]->name);
+    ret = orc_test_gcc_compile (programs[i]);
+    if (ret == ORC_TEST_FAILED) {
+      error = TRUE;
+    }
+  }
+
+  if (error) return 1;
+  return 0;
+}
+
+
+static char *
+read_file (const char *filename)
+{
+  FILE *file = NULL;
+  char *contents = NULL;
+  long size;
+  int ret;
+
+  file = fopen (filename, "r");
+  if (file == NULL) return NULL;
+
+  ret = fseek (file, 0, SEEK_END);
+  if (ret < 0) goto bail;
+
+  size = ftell (file);
+  if (size < 0) goto bail;
+
+  ret = fseek (file, 0, SEEK_SET);
+  if (ret < 0) goto bail;
+
+  contents = malloc (size + 1);
+  if (contents == NULL) goto bail;
+
+  ret = fread (contents, size, 1, file);
+  if (ret < 0) goto bail;
+
+  contents[size] = 0;
+
+  return contents;
+bail:
+  /* something failed */
+  if (file) fclose (file);
+  if (contents) free (contents);
+
+  return NULL;
+}
+