diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cmake/target_library/CMakeLists.txt | 43 | ||||
-rw-r--r-- | tests/cmake/target_library/srcfile.cmake | 6 | ||||
-rw-r--r-- | tests/core/test_simd4.in | 39 | ||||
-rw-r--r-- | tests/core/test_simd4.out | 1 | ||||
-rw-r--r-- | tests/glfw.c | 4 | ||||
-rw-r--r-- | tests/sdl_image.c | 10 | ||||
-rw-r--r-- | tests/test_core.py | 9 | ||||
-rw-r--r-- | tests/test_other.py | 16 |
8 files changed, 121 insertions, 7 deletions
diff --git a/tests/cmake/target_library/CMakeLists.txt b/tests/cmake/target_library/CMakeLists.txt new file mode 100644 index 00000000..c7023192 --- /dev/null +++ b/tests/cmake/target_library/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 2.8) + +project(test_cmake) + +option(BUILD_SHARED_LIBS "Build with shared libraries." OFF) + +if (CMAKE_BUILD_TYPE STREQUAL Debug) + SET(linkFlags "-g4") +else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled. + SET(linkFlags "-O2") +endif() + +set(MAX_SRC_FILE_INDEX 30) +SET(TEST_SRC_FILE_BASE_NAME "this_is_a_test_src_file_with_a_quite_lengthy_name_to_simulate_very_long_command_line_length_problems_on_windows_") + + +foreach(i RANGE ${MAX_SRC_FILE_INDEX}) + set (TEST_FUNCTION_NAME "FooBar_${i}") + configure_file("srcfile.cmake" "${TEST_SRC_FILE_BASE_NAME}${i}.c") + configure_file("srcfile.cmake" "${TEST_SRC_FILE_BASE_NAME}${i}.cpp") + list(APPEND TEST_SOURCES "${TEST_SRC_FILE_BASE_NAME}${i}.c" "${TEST_SRC_FILE_BASE_NAME}${i}.cpp") +endforeach() + +add_library(test_cmake ${TEST_SOURCES}) + +if (WIN32) + message(FATAL_ERROR "WIN32 should not be defined when cross-compiling!") +endif() + +if (APPLE) + message(FATAL_ERROR "APPLE should not be defined when cross-compiling!") +endif() + +if (NOT EMSCRIPTEN) + message(FATAL_ERROR "EMSCRIPTEN should be defined when cross-compiling!") +endif() + +if (NOT CMAKE_C_SIZEOF_DATA_PTR) + message(FATAL_ERROR "CMAKE_C_SIZEOF_DATA_PTR was not defined!") +endif() + +# GOTCHA: If your project has custom link flags, these must be set *before* calling any of the em_link_xxx functions! +set_target_properties(test_cmake PROPERTIES LINK_FLAGS "${linkFlags}") diff --git a/tests/cmake/target_library/srcfile.cmake b/tests/cmake/target_library/srcfile.cmake new file mode 100644 index 00000000..10e9e6f8 --- /dev/null +++ b/tests/cmake/target_library/srcfile.cmake @@ -0,0 +1,6 @@ +#include <stdio.h> + +void @TEST_FUNCTION_NAME@() +{ + printf("@TEST_FUNCTION_NAME@"); +} diff --git a/tests/core/test_simd4.in b/tests/core/test_simd4.in new file mode 100644 index 00000000..b597d8a3 --- /dev/null +++ b/tests/core/test_simd4.in @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <xmmintrin.h> + +static __inline__ __m128 __attribute__((__always_inline__)) +_mm_load_ps(const float *__p) +{ + return *(__m128*)__p; +} + +float simdAverage(float *src, int len) { + __m128 sumx4 = _mm_setzero_ps(); + for (int i = 0; i < len; i += 4) { + __m128 v = _mm_load_ps(src); + sumx4 = _mm_add_ps(sumx4, v); + src += 4; + } + float sumx4_mem[4]; + float *sumx4_ptr = sumx4_mem; + _mm_store_ps(sumx4_ptr, sumx4); + return (sumx4_mem[0] + sumx4_mem[1] + + sumx4_mem[2] + sumx4_mem[3])/len; +} + +void initArray(float *src, int len) { + for (int i = 0; i < len; ++i) { + src[i] = 0.1 * i; + } +} + +int main() { + const int len = 100000; + float src[len]; + float result = 0.0; + + initArray(src, len); + + result = simdAverage(src, len); + printf("averagex4 result: %.1f\n", result); +}
\ No newline at end of file diff --git a/tests/core/test_simd4.out b/tests/core/test_simd4.out new file mode 100644 index 00000000..99449772 --- /dev/null +++ b/tests/core/test_simd4.out @@ -0,0 +1 @@ +averagex4 result: 4999.9
\ No newline at end of file diff --git a/tests/glfw.c b/tests/glfw.c index 79199d9a..cbdc81fe 100644 --- a/tests/glfw.c +++ b/tests/glfw.c @@ -376,6 +376,10 @@ void PullInfo(){ extension = "GL_EXT_framebuffer_object"; printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); + extension = "glBindBuffer"; + void* proc_addr = glfwGetProcAddress(extension); + printf("'%s' extension proc address is %p.\n", extension, proc_addr); + printf("Sleeping 1 sec...\n"); glfwSleep(1); printf("...Done.\n"); diff --git a/tests/sdl_image.c b/tests/sdl_image.c index 523f8903..9639ea37 100644 --- a/tests/sdl_image.c +++ b/tests/sdl_image.c @@ -4,6 +4,7 @@ #include <assert.h> #include <emscripten.h> #include <unistd.h> +#include <stdlib.h> int testImage(SDL_Surface* screen, const char* fileName) { SDL_Surface *image = IMG_Load(fileName); @@ -18,7 +19,16 @@ int testImage(SDL_Surface* screen, const char* fileName) { int result = image->w; SDL_BlitSurface (image, NULL, screen, NULL); + + int w, h; + char *data = emscripten_get_preloaded_image_data(fileName, &w, &h); + + assert(data); + assert(w == image->w); + assert(h == image->h); + SDL_FreeSurface (image); + free(data); return result; } diff --git a/tests/test_core.py b/tests/test_core.py index bcb03830..b9057f4e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4892,6 +4892,15 @@ return malloc(size); self.do_run_from_file(src, output) + def test_simd4(self): + # test_simd4 is to test phi node handling of SIMD path + if Settings.ASM_JS: Settings.ASM_JS = 2 # does not validate + + test_path = path_from_root('tests', 'core', 'test_simd4') + src, output = (test_path + s for s in ('.in', '.out')) + + self.do_run_from_file(src, output) + def test_gcc_unmangler(self): if os.environ.get('EMCC_FAST_COMPILER') == '0': Settings.NAMED_GLOBALS = 1 # test coverage for this; fastcomp never names globals diff --git a/tests/test_other.py b/tests/test_other.py index 665832ee..39796b71 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -207,7 +207,8 @@ Options that are modified or new in %s include: (['-O2'], lambda generated: '// The Module object' not in generated, 'with opts, no comments in shell code'), (['-O2', '-g2'], lambda generated: '// The Module object' not in generated, 'with -g2, no comments in shell code'), (['-O2', '-g3'], lambda generated: '// The Module object' in generated, 'with -g3, yes comments in shell code'), - (['-O2', '-profiling'], lambda generated: '// The Module object' in generated, 'with -profiling, yes comments in shell code'), + (['-O2', '-profiling'], lambda generated: '// The Module object' in generated or os.environ.get('EMCC_FAST_COMPILER') == '0', 'with -profiling, yes comments in shell code (in fastcomp)'), + ]: print params, text self.clear() @@ -354,9 +355,10 @@ f.close() except KeyError: postbuild = None - cmake_cases = ['target_js', 'target_html'] - cmake_outputs = ['test_cmake.js', 'hello_world_gles.html'] - for i in range(0, 2): + cmake_cases = ['target_js', 'target_html', 'target_library', 'target_library'] + cmake_outputs = ['test_cmake.js', 'hello_world_gles.html', 'libtest_cmake.a', 'libtest_cmake.so'] + cmake_arguments = ['', '', '-DBUILD_SHARED_LIBS=OFF', '-DBUILD_SHARED_LIBS=ON'] + for i in range(0, len(cmake_cases)): for configuration in ['Debug', 'Release']: # CMake can be invoked in two ways, using 'emconfigure cmake', or by directly running 'cmake'. # Test both methods. @@ -374,11 +376,11 @@ f.close() if invoke_method == 'cmake': # Test invoking cmake directly. cmd = ['cmake', '-DCMAKE_TOOLCHAIN_FILE='+path_from_root('cmake', 'Platform', 'Emscripten.cmake'), - '-DCMAKE_BUILD_TYPE=' + configuration, '-G', generator, cmakelistsdir] + '-DCMAKE_BUILD_TYPE=' + configuration, cmake_arguments[i], '-G', generator, cmakelistsdir] else: # Test invoking via 'emconfigure cmake' - cmd = [emconfigure, 'cmake', '-DCMAKE_BUILD_TYPE=' + configuration, '-G', generator, cmakelistsdir] - + cmd = [emconfigure, 'cmake', '-DCMAKE_BUILD_TYPE=' + configuration, cmake_arguments[i], '-G', generator, cmakelistsdir] + ret = Popen(cmd, stdout=None if verbose_level >= 2 else PIPE, stderr=None if verbose_level >= 1 else PIPE).communicate() if len(ret) > 1 and ret[1] != None and len(ret[1].strip()) > 0: logging.error(ret[1]) # If there were any errors, print them directly to console for diagnostics. |