@needs_dlfcn
def test_dlfcn_alignment_and_zeroing(self):
    self.prep_dlfcn_lib()
    self.set_setting('INITIAL_MEMORY', ((16 * 1024) * 1024))
    lib_src = '\n      extern "C" {\n        int prezero = 0;\n        __attribute__((aligned(1024))) int superAligned = 12345;\n        int postzero = 0;\n      }\n      '
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.cpp')
    self.build_dlfcn_lib(lib_src, dirname, filename)
    for i in range(10):
        curr = ('%d.so' % i)
        shutil.copyfile('liblib.so', curr)
        self.emcc_args += ['--embed-file', curr]
    self.prep_dlfcn_main()
    self.set_setting('INITIAL_MEMORY', ((128 * 1024) * 1024))
    src = '\n      #include <stdio.h>\n      #include <stdlib.h>\n      #include <string.h>\n      #include <dlfcn.h>\n      #include <assert.h>\n      #include <emscripten.h>\n\n      int main() {\n        printf("\'prepare\' memory with non-zero inited stuff\\n");\n        int num = 120 * 1024 * 1024; // total is 128; we\'ll use 5*5 = 25 at least, so allocate pretty much all of it\n        void* mem = malloc(num);\n        assert(mem);\n        printf("setting this range to non-zero: %d - %d\\n", int(mem), int(mem) + num);\n        memset(mem, 1, num);\n        EM_ASM({\n          var value = HEAP8[64*1024*1024];\n          out(\'verify middle of memory is non-zero: \' + value);\n          assert(value === 1);\n        });\n        free(mem);\n        for (int i = 0; i < 10; i++) {\n          char curr[] = "?.so";\n          curr[0] = \'0\' + i;\n          printf("loading %s\\n", curr);\n          void* lib_handle = dlopen(curr, RTLD_NOW);\n          if (!lib_handle) {\n            puts(dlerror());\n            assert(0);\n          }\n          printf("getting superAligned\\n");\n          int* superAligned = (int*)dlsym(lib_handle, "superAligned");\n          assert(superAligned);\n          assert(int(superAligned) % 1024 == 0); // alignment\n          printf("checking value of superAligned, at %d\\n", superAligned);\n          assert(*superAligned == 12345); // value\n          printf("getting prezero\\n");\n          int* prezero = (int*)dlsym(lib_handle, "prezero");\n          assert(prezero);\n          printf("checking value of prezero, at %d\\n", prezero);\n          assert(*prezero == 0);\n          *prezero = 1;\n          assert(*prezero != 0);\n          printf("getting postzero\\n");\n          int* postzero = (int*)dlsym(lib_handle, "postzero");\n          printf("checking value of postzero, at %d\\n", postzero);\n          assert(postzero);\n          printf("checking value of postzero\\n");\n          assert(*postzero == 0);\n          *postzero = 1;\n          assert(*postzero != 0);\n        }\n        printf("success.\\n");\n        return 0;\n      }\n      '
    self.do_run(src, 'success.\n')
@needs_dlfcn
def test_dlfcn_alignment_and_zeroing(self):
    self.prep_dlfcn_lib()
    self.set_setting('INITIAL_MEMORY', ((16 * 1024) * 1024))
    lib_src = '\n      extern "C" {\n        int prezero = 0;\n        __attribute__((aligned(1024))) int superAligned = 12345;\n        int postzero = 0;\n      }\n      '
    dirname = self.get_dir()
    filename = os.path.join(dirname, 'liblib.cpp')
    self.build_dlfcn_lib(lib_src, dirname, filename)
    for i in range(10):
        curr = ('%d.so' % i)
        shutil.copyfile('liblib.so', curr)
        self.emcc_args += ['--embed-file', curr]
    self.prep_dlfcn_main()
    self.set_setting('INITIAL_MEMORY', ((128 * 1024) * 1024))
    src = '\n      #include <stdio.h>\n      #include <stdlib.h>\n      #include <string.h>\n      #include <dlfcn.h>\n      #include <assert.h>\n      #include <emscripten.h>\n\n      int main() {\n        printf("\'prepare\' memory with non-zero inited stuff\\n");\n        int num = 120 * 1024 * 1024; // total is 128; we\'ll use 5*5 = 25 at least, so allocate pretty much all of it\n        void* mem = malloc(num);\n        assert(mem);\n        printf("setting this range to non-zero: %d - %d\\n", int(mem), int(mem) + num);\n        memset(mem, 1, num);\n        EM_ASM({\n          var value = HEAP8[64*1024*1024];\n          out(\'verify middle of memory is non-zero: \' + value);\n          assert(value === 1);\n        });\n        free(mem);\n        for (int i = 0; i < 10; i++) {\n          char curr[] = "?.so";\n          curr[0] = \'0\' + i;\n          printf("loading %s\\n", curr);\n          void* lib_handle = dlopen(curr, RTLD_NOW);\n          if (!lib_handle) {\n            puts(dlerror());\n            assert(0);\n          }\n          printf("getting superAligned\\n");\n          int* superAligned = (int*)dlsym(lib_handle, "superAligned");\n          assert(superAligned);\n          assert(int(superAligned) % 1024 == 0); // alignment\n          printf("checking value of superAligned, at %d\\n", superAligned);\n          assert(*superAligned == 12345); // value\n          printf("getting prezero\\n");\n          int* prezero = (int*)dlsym(lib_handle, "prezero");\n          assert(prezero);\n          printf("checking value of prezero, at %d\\n", prezero);\n          assert(*prezero == 0);\n          *prezero = 1;\n          assert(*prezero != 0);\n          printf("getting postzero\\n");\n          int* postzero = (int*)dlsym(lib_handle, "postzero");\n          printf("checking value of postzero, at %d\\n", postzero);\n          assert(postzero);\n          printf("checking value of postzero\\n");\n          assert(*postzero == 0);\n          *postzero = 1;\n          assert(*postzero != 0);\n        }\n        printf("success.\\n");\n        return 0;\n      }\n      '
    self.do_run(src, 'success.\n')