diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-09-14 00:52:24 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 7d663615b2a44715e7447a40cae467d7d4e38b9c (patch) | |
tree | 612e81f55ca73c3da868bd2ab6cd96ae6ac30a15 /tests | |
parent | 7103d3a1df6c7fee6e8efbe3588204d1e869004e (diff) |
Start on opengl test, fix stack alignment before call (sys-v)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glfw.amal | 9 | ||||
-rw-r--r-- | tests/main.c | 102 |
2 files changed, 105 insertions, 6 deletions
diff --git a/tests/glfw.amal b/tests/glfw.amal new file mode 100644 index 0000000..8957127 --- /dev/null +++ b/tests/glfw.amal @@ -0,0 +1,9 @@ +extern const glfwInit: fn() i32; +extern const glfwTerminate: fn() i32; // should return void.... +extern const glfwCreateWindow: fn(x: i32, y: i32, title: str, monitor: usize, share: usize) usize; + +const main = fn { + glfwInit(); + glfwCreateWindow(50, 50, "hello, world", 0, 0); + glfwTerminate(); +}
\ No newline at end of file diff --git a/tests/main.c b/tests/main.c index eec3a78..1a86769 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,12 +1,12 @@ -#include <stdio.h> -#include <string.h> #include "../include/compiler.h" #include "../include/std/hash_map.h" #include "../include/std/hash.h" #include "../include/std/log.h" #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <GLFW/glfw3.h> static int num_threads = 0; static int num_successful_tests = 0; @@ -142,6 +142,93 @@ static int print_extern_num(i64 num) { return 0; } +static void test_load_gl(void) { + #if 0 + GLFWwindow* window; + + /* Initialize the library */ + if (!glfwInit()) + FAIL_TEST(full_path); + + /* Create a windowed mode window and its OpenGL context */ + window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); + if (!window) { + glfwTerminate(); + FAIL_TEST(full_path); + } + + /* Make the window's context current */ + glfwMakeContextCurrent(window); + + /* Loop until the user closes the window */ + while (!glfwWindowShouldClose(window)) + { + /* Render here */ + glClear(GL_COLOR_BUFFER_BIT); + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + + /* Swap front and back buffers */ + glfwSwapBuffers(window); + + /* Poll for and process events */ + glfwPollEvents(); + } + + glfwTerminate(); + #endif + char *full_path = get_full_path("tests/glfw.amal"); + amal_compiler_options options; + amal_program program; + int result; + + amal_compiler_options_init(&options); + options.num_threads = num_threads; + ++num_tests_run; + + if(amal_program_init(&program) != 0) { + fprintf(stderr, "Failed to initialize amal program\n"); + FAIL_TEST_CLEANUP(full_path); + } + + printf("glfw init ptr: %p, glfw terminate: %p\n", glfwInit, glfwTerminate); + + if(amal_program_register_extern_func(&program, create_buffer_view_auto("glfwInit"), glfwInit, 0) != 0) { + fprintf(stderr, "Unexpected error (alloc failure)\n"); + FAIL_TEST_CLEANUP(full_path); + } + if(amal_program_register_extern_func(&program, create_buffer_view_auto("glfwTerminate"), glfwTerminate, 0) != 0) { + fprintf(stderr, "Unexpected error (alloc failure)\n"); + FAIL_TEST_CLEANUP(full_path); + } + if(amal_program_register_extern_func(&program, create_buffer_view_auto("glfwCreateWindow"), glfwCreateWindow, sizeof(int) + sizeof(int) + sizeof(const char*) + sizeof(void*) + sizeof(void*)) != 0) { + fprintf(stderr, "Unexpected error (alloc failure)\n"); + FAIL_TEST_CLEANUP(full_path); + } + if(amal_program_register_extern_func(&program, create_buffer_view_auto("print_extern_num"), print_extern_num, sizeof(i64)) != 0) { + fprintf(stderr, "Unexpected error (alloc failure)\n"); + FAIL_TEST_CLEANUP(full_path); + } + + result = amal_compiler_load_file(&options, &program, full_path); + if(result != AMAL_COMPILER_OK) { + fprintf(stderr, "Failed to load file %s, result: %d\n", full_path, result); + FAIL_TEST_CLEANUP(full_path); + } + + result = amal_program_run(&program); + if(result != 0) { + fprintf(stderr, "Failed to run the program %s, result: %d\n", full_path, result); + FAIL_TEST_CLEANUP(full_path); + } + + fprintf(stderr, "Test succeeded as expected: %s\n", full_path); + ++num_successful_tests; + + cleanup: + amal_program_deinit(&program); + free(full_path); +} + static void test_load(const char *filepath) { amal_compiler_options options; amal_program program; @@ -155,14 +242,14 @@ static void test_load(const char *filepath) { if(amal_program_init(&program) != 0) { fprintf(stderr, "Failed to initialize amal program\n"); - FAIL_TEST(full_path); + FAIL_TEST_CLEANUP(full_path); } - if(amal_program_add_extern_func(&program, create_buffer_view("print_extern", 12), print_extern, 0) != 0) { + if(amal_program_register_extern_func(&program, create_buffer_view_auto("print_extern"), print_extern, 0) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); FAIL_TEST_CLEANUP(full_path); } - if(amal_program_add_extern_func(&program, create_buffer_view("print_extern_num", 16), print_extern_num, sizeof(i64)) != 0) { + if(amal_program_register_extern_func(&program, create_buffer_view_auto("print_extern_num"), print_extern_num, sizeof(i64)) != 0) { fprintf(stderr, "Unexpected error (alloc failure)\n"); FAIL_TEST_CLEANUP(full_path); } @@ -301,7 +388,10 @@ int main(int argc, char **argv) { if(argc == 1) { run_all_tests(); } else if(argc == 2) { - test_load(argv[1]); + if(strcmp(argv[1], "opengl") == 0) + test_load_gl(); + else + test_load(argv[1]); } else { fprintf(stderr, "usage: test [test-file-path]\n"); fprintf(stderr, "If you run test without any files then all tests will run.\n"); |