+2015-02-06 David Malcolm <dmalcolm@redhat.com>
+
+ PR jit/64752
+ * jit.dg/create-code-for-hello-world-executable.h: New file, taken
+ from jit.dg/test-compile-to-executable.c's create_code, with a
+ clarification of the output message.
+ * jit.dg/harness.h (CHECK_NO_ERRORS): Add test and __func__ to the
+ pass/fail message.
+ (test_jit): Use CHECK_NO_ERRORS when calling
+ gcc_jit_context_compile_to_file.
+ * jit.dg/jit.exp (jit-dg-test): Update grep for rename of
+ jit-verify-compile-to-file to jit-verify-output-file-was-created.
+ (jit-setup-compile-to-file): Likewise. Add a verbose comment
+ about deletions that are attempted.
+ (jit-verify-compile-to-file): Rename to...
+ (jit-verify-output-file-was-created): ...this, and drop the
+ attempt to run "file" and verify the output.
+ (jit-verify-assembler): New function.
+ (jit-verify-object): New function.
+ (jit-verify-dynamic-library): New function.
+ * jit.dg/test-compile-to-assembler.c (create_code): Eliminate in
+ favor of an implementation from new file
+ create-code-for-hello-world-executable.h, which also adds a
+ "main".
+ (dg-final): Replace jit-verify-compile-to-file with
+ jit-verify-output-file-was-created, and invoke new function
+ jit-verify-assembler.
+ * jit.dg/test-compile-to-dynamic-library.c (create_code): Clarify
+ the output message.
+ (dg-final): Replace jit-verify-compile-to-file with
+ jit-verify-output-file-was-created, and invoke new function
+ jit-verify-dynamic-library.
+ * jit.dg/test-compile-to-executable.c (create_code): Eliminate in
+ favor of an implementation from new file
+ create-code-for-hello-world-executable.h, which also adds a
+ "main".
+ (dg-final): Replace jit-verify-compile-to-file with
+ jit-verify-output-file-was-created. Strengthen the expected stdout
+ from the built executable.
+ * jit.dg/test-compile-to-object.c (create_code): Eliminate in
+ favor of an implementation from new file
+ create-code-for-hello-world-executable.h, which also adds a
+ "main".
+ (dg-final): Replace jit-verify-compile-to-file with
+ jit-verify-output-file-was-created, and invoke new function
+ jit-verify-object.
+ * jit.dg/verify-dynamic-library.c: New source file.
+
2015-02-06 Sebastian Pop <s.pop@samsung.com>
Brian Rzycki <b.rzycki@samsung.com>
do { \
const char *err = gcc_jit_context_get_first_error (CTXT); \
if (err) \
- fail ("error unexpectedly occurred: %s", err); \
+ fail ("%s: %s: error unexpectedly occurred: %s", test, __func__, err); \
else \
- pass ("no errors occurred"); \
+ pass ("%s: %s: no errors occurred", test, __func__); \
} while (0)
/* Hooks that testcases should provide. */
gcc_jit_context_compile_to_file (ctxt,
(OUTPUT_KIND),
(OUTPUT_FILENAME));
+ CHECK_NO_ERRORS (ctxt);
#else /* #ifdef TEST_COMPILING_TO_FILE */
/* This actually calls into GCC and runs the build, all
in a mutex for now. */
append extra_tool_flags " -lpthread"
}
- # Any test case that uses
- # { dg-final { jit-verify-compile-to-file FOO } }
+ # Any test case that uses jit-verify-output-file-was-created
# needs to call jit-setup-compile-to-file here.
# (is there a better way to handle setup/finish pairs in dg?)
- set tmp [grep $prog "jit-verify-compile-to-file"]
+ set tmp [grep $prog "jit-verify-output-file-was-created"]
if {![string match "" $tmp]} {
jit-setup-compile-to-file $prog
}
return ""
}
-# For testcases that use jit-verify-compile-to-file,
+# For testcases that use jit-verify-output-file-was-created
# delete OUTPUT_FILENAME beforehand, to ensure that the
# testcase is indeed creating it.
set output_filename [jit-get-output-filename $prog]
verbose " output_filename: $output_filename"
if {![string match "" $output_filename]} {
+ verbose " deleting any $output_filename"
catch "exec rm -f $output_filename"
}
}
-# Locate OUTPUT_FILENAME within the testcase. Verify
-# that a file with that name was created, and that
-# the output of running the "file" utility on it
-# matches the given regex.
-# For use by the various test-compile-to-*.c testcases.
-
-proc jit-verify-compile-to-file {args} {
- verbose "jit-verify-compile-to-file: $args"
-
- set file_regex [lindex $args 0]
- verbose "file_regex: $file_regex"
+proc jit-verify-output-file-was-created { args } {
+ verbose "jit-verify-output-file-was-created: $args"
upvar 2 prog prog
verbose "prog: $prog"
pass "$output_filename exists"
} else {
fail "$output_filename does not exist"
- return
- }
-
- # Run "file" on OUTPUT_FILENAME, and verify that the output
- # matches $file_regex.
- spawn -noecho "file" $output_filename
- set file_id $spawn_id
- expect "\n" {
- verbose "got newline: $expect_out(buffer)"
- set classification $expect_out(buffer)
- verbose "classification: $classification"
- if { [regexp $file_regex $classification] } {
- pass "'file' output on $output_filename matched: $file_regex"
- } else {
- fail "'file' output on $output_filename did not match: $file_regex"
- }
}
- set $spawn_id $file_id
- close
}
# Verify that the given file exists, and is executable.
}
}
+# Assuming that a .s file has been written out named
+# OUTPUT_FILENAME, invoke the driver to try to turn it into
+# an executable, and try to run the result.
+# For use by the test-compile-to-assembler.c testcase.
+proc jit-verify-assembler { args } {
+ verbose "jit-verify-assembler: $args"
+
+ set dg-output-text [lindex $args 0]
+ verbose "dg-output-text: ${dg-output-text}"
+
+ upvar 2 name name
+ verbose "name: $name"
+
+ upvar 2 prog prog
+ verbose "prog: $prog"
+ set asm_filename [jit-get-output-filename $prog]
+ verbose " asm_filename: ${asm_filename}"
+
+ # Name the built executable as OUTPUT_FILENAME with
+ # ".exe" appended.
+ set executable_from_asm ${asm_filename}.exe
+ verbose " executable_from_asm: ${executable_from_asm}"
+
+ # Invoke the driver to assemble/link the .s file to the .exe
+ set comp_output [gcc_target_compile \
+ ${asm_filename} \
+ ${executable_from_asm} \
+ "executable" \
+ "{}"]
+ if ![jit_check_compile \
+ "$name" \
+ "assemble/link of ${asm_filename}" \
+ ${executable_from_asm} \
+ $comp_output] then {
+ return
+ }
+
+ # Verify that the executable was created.
+ if { [file exists $executable_from_asm] == 1} {
+ pass "$executable_from_asm exists"
+ } else {
+ fail "$executable_from_asm does not exist"
+ }
+
+ # Run it and verify that the output matches the regex.
+ jit-run-executable ${executable_from_asm} ${dg-output-text}
+}
+
+# Assuming that a .o file has been written out named
+# OUTPUT_FILENAME, invoke the driver to try to turn it into
+# an executable, and try to run the result.
+# For use by the test-compile-to-object.c testcase.
+proc jit-verify-object { args } {
+ verbose "jit-verify-object: $args"
+
+ set dg-output-text [lindex $args 0]
+ verbose "dg-output-text: ${dg-output-text}"
+
+ upvar 2 name name
+ verbose "name: $name"
+
+ upvar 2 prog prog
+ verbose "prog: $prog"
+ set obj_filename [jit-get-output-filename $prog]
+ verbose " obj_filename: ${obj_filename}"
+
+ # Name the linked executable as OUTPUT_FILENAME with
+ # ".exe" appended.
+ set executable_from_obj ${obj_filename}.exe
+ verbose " executable_from_obj: ${executable_from_obj}"
+
+ # Invoke the driver to link the .o file to the .exe
+ set comp_output [gcc_target_compile \
+ ${obj_filename} \
+ ${executable_from_obj} \
+ "executable" \
+ "{}"]
+ if ![jit_check_compile \
+ "$name" \
+ "link of ${obj_filename}" \
+ ${executable_from_obj} \
+ $comp_output] then {
+ return
+ }
+
+ # Verify that the executable was created.
+ if { [file exists $executable_from_obj] == 1} {
+ pass "$executable_from_obj exists"
+ } else {
+ fail "$executable_from_obj does not exist"
+ }
+
+ # Run it and verify that the output matches the regex.
+ jit-run-executable ${executable_from_obj} ${dg-output-text}
+}
+
+# Assuming that a .so file has been written out named
+# OUTPUT_FILENAME, build a test executable to use it,
+# and try to run the result.
+# For use by the test-compile-to-dynamic-library.c testcase.
+proc jit-verify-dynamic-library { args } {
+ verbose "jit-verify-object: $args"
+
+ global srcdir
+ global subdir
+
+ set dg-output-text [lindex $args 0]
+ verbose "dg-output-text: ${dg-output-text}"
+
+ upvar 2 name name
+ verbose "name: $name"
+
+ upvar 2 prog prog
+ verbose "prog: $prog"
+ set obj_filename [jit-get-output-filename $prog]
+ verbose " obj_filename: ${obj_filename}"
+
+ # Build a test executable from
+ # verify-dynamic-library.c
+ set test_src "verify-dynamic-library.c"
+ set test_executable ${test_src}.exe
+ verbose " test_executable: ${test_executable}"
+
+ # Invoke the driver to build the test executable
+ set comp_output [gcc_target_compile \
+ $srcdir/$subdir/${test_src} \
+ ${test_executable} \
+ "executable" \
+ "{additional_flags=-ldl}"]
+ if ![jit_check_compile \
+ "$name" \
+ "build of ${test_executable}" \
+ ${test_executable} \
+ $comp_output] then {
+ return
+ }
+
+ # Verify that the test executable was created.
+ if { [file exists $test_executable] == 1} {
+ pass "$test_executable exists"
+ } else {
+ fail "$test_executable does not exist"
+ }
+
+ # Run it and verify that the output matches the regex.
+ jit-run-executable ${test_executable} ${dg-output-text}
+}
+
# A way to invoke "jit-run-executable" with the given regex,
# using OUTPUT_FILENAME within the testcase to determine
# the name of the executable to run.
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
#define OUTPUT_FILENAME "output-of-test-compile-to-assembler.c.s"
#include "harness.h"
+#include "create-code-for-hello-world-executable.h"
-void
-create_code (gcc_jit_context *ctxt, void *user_data)
-{
- /* Let's try to inject the equivalent of:
- void
- hello_world (const char *name)
- {
- // a test comment
- printf ("hello %s\n", name);
- }
- */
- gcc_jit_type *void_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
- gcc_jit_type *const_char_ptr_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
- gcc_jit_param *param_name =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "name");
- gcc_jit_function *func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_EXPORTED,
- void_type,
- "hello_world",
- 1, ¶m_name,
- 0);
-
- gcc_jit_param *param_format =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "format");
- gcc_jit_function *printf_func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_IMPORTED,
- gcc_jit_context_get_type (
- ctxt, GCC_JIT_TYPE_INT),
- "printf",
- 1, ¶m_format,
- 1);
- gcc_jit_rvalue *args[2];
- args[0] = gcc_jit_context_new_string_literal (ctxt, "hello %s\n");
- args[1] = gcc_jit_param_as_rvalue (param_name);
-
- gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
-
- gcc_jit_block_add_comment (
- block, NULL,
- "a test comment");
-
- gcc_jit_block_add_eval (
- block, NULL,
- gcc_jit_context_new_call (ctxt,
- NULL,
- printf_func,
- 2, args));
- gcc_jit_block_end_with_void_return (block, NULL);
-}
-
-/* { dg-final { jit-verify-compile-to-file "assembler source text" } } */
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-assembler "hello from ./output-of-test-compile-to-assembler.c.s.exe" } } */
hello_world (const char *name)
{
// a test comment
- printf ("hello %s\n", name);
+ printf ("hello from %s\n", name);
}
*/
gcc_jit_type *void_type =
1, ¶m_format,
1);
gcc_jit_rvalue *args[2];
- args[0] = gcc_jit_context_new_string_literal (ctxt, "hello %s\n");
+ args[0] = gcc_jit_context_new_string_literal (ctxt, "hello from %s\n");
args[1] = gcc_jit_param_as_rvalue (param_name);
gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
gcc_jit_block_end_with_void_return (block, NULL);
}
-/* { dg-final { jit-verify-compile-to-file "shared object.+dynamically linked" } } */
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-dynamic-library "hello from ./verify-dynamic-library.c.exe" } } */
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_EXECUTABLE
#define OUTPUT_FILENAME "output-of-test-compile-to-executable.c.exe"
#include "harness.h"
+#include "create-code-for-hello-world-executable.h"
-void
-create_code (gcc_jit_context *ctxt, void *user_data)
-{
- /* Let's try to inject the equivalent of:
- static void
- hello_world (const char *name)
- {
- // a test comment
- printf ("hello %s\n", name);
- }
-
- extern int
- main (int argc, char **argv)
- {
- hello_world (argv[0]);
- return 0;
- }
- */
- gcc_jit_type *void_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
- gcc_jit_type *const_char_ptr_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
- gcc_jit_param *param_name =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "name");
- gcc_jit_function *func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_INTERNAL,
- void_type,
- "hello_world",
- 1, ¶m_name,
- 0);
-
- gcc_jit_param *param_format =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "format");
- gcc_jit_function *printf_func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_IMPORTED,
- gcc_jit_context_get_type (
- ctxt, GCC_JIT_TYPE_INT),
- "printf",
- 1, ¶m_format,
- 1);
- gcc_jit_rvalue *args[2];
- args[0] = gcc_jit_context_new_string_literal (ctxt, "hello %s\n");
- args[1] = gcc_jit_param_as_rvalue (param_name);
-
- gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
-
- gcc_jit_block_add_comment (
- block, NULL,
- "a test comment");
-
- gcc_jit_block_add_eval (
- block, NULL,
- gcc_jit_context_new_call (ctxt,
- NULL,
- printf_func,
- 2, args));
- gcc_jit_block_end_with_void_return (block, NULL);
-
- gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
- gcc_jit_param *param_argc =
- gcc_jit_context_new_param (ctxt, NULL, int_type, "argc");
- gcc_jit_type *char_ptr_ptr_type =
- gcc_jit_type_get_pointer (
- gcc_jit_type_get_pointer (
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR)));
- gcc_jit_param *param_argv =
- gcc_jit_context_new_param (ctxt, NULL, char_ptr_ptr_type, "argv");
- gcc_jit_param *params[2] = {param_argc, param_argv};
- gcc_jit_function *func_main =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_EXPORTED,
- int_type,
- "main",
- 2, params,
- 0);
- block = gcc_jit_function_new_block (func_main, NULL);
- gcc_jit_rvalue *zero = gcc_jit_context_zero (ctxt, int_type);
- args[0] = gcc_jit_context_new_cast (
- ctxt,
- NULL,
- gcc_jit_lvalue_as_rvalue (
- gcc_jit_context_new_array_access (
- ctxt,
- NULL,
- gcc_jit_param_as_rvalue (param_argv),
- zero)),
- const_char_ptr_type);
- gcc_jit_block_add_eval (
- block, NULL,
- gcc_jit_context_new_call (ctxt,
- NULL,
- func,
- 1, args));
- gcc_jit_block_end_with_return (block, NULL, zero);
-}
-
-/* { dg-final { jit-verify-compile-to-file "executable" } } */
-/* { dg-final { jit-verify-executable "hello .*" } } */
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-executable "hello from ./output-of-test-compile-to-executable.c.exe" } } */
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_OBJECT_FILE
#define OUTPUT_FILENAME "output-of-test-compile-to-object.c.o"
#include "harness.h"
+#include "create-code-for-hello-world-executable.h"
-void
-create_code (gcc_jit_context *ctxt, void *user_data)
-{
- /* Let's try to inject the equivalent of:
- void
- hello_world (const char *name)
- {
- // a test comment
- printf ("hello %s\n", name);
- }
- */
- gcc_jit_type *void_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
- gcc_jit_type *const_char_ptr_type =
- gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
- gcc_jit_param *param_name =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "name");
- gcc_jit_function *func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_EXPORTED,
- void_type,
- "hello_world",
- 1, ¶m_name,
- 0);
-
- gcc_jit_param *param_format =
- gcc_jit_context_new_param (ctxt, NULL, const_char_ptr_type, "format");
- gcc_jit_function *printf_func =
- gcc_jit_context_new_function (ctxt, NULL,
- GCC_JIT_FUNCTION_IMPORTED,
- gcc_jit_context_get_type (
- ctxt, GCC_JIT_TYPE_INT),
- "printf",
- 1, ¶m_format,
- 1);
- gcc_jit_rvalue *args[2];
- args[0] = gcc_jit_context_new_string_literal (ctxt, "hello %s\n");
- args[1] = gcc_jit_param_as_rvalue (param_name);
-
- gcc_jit_block *block = gcc_jit_function_new_block (func, NULL);
-
- gcc_jit_block_add_comment (
- block, NULL,
- "a test comment");
-
- gcc_jit_block_add_eval (
- block, NULL,
- gcc_jit_context_new_call (ctxt,
- NULL,
- printf_func,
- 2, args));
- gcc_jit_block_end_with_void_return (block, NULL);
-}
-
-/* { dg-final { jit-verify-compile-to-file "relocatable" } } */
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-object "hello from ./output-of-test-compile-to-object.c.o.exe" } } */