Beispiel #1
0
    def test_emcc_multiprocess_cache_access(self):
        restore_and_set_up()

        create_file(
            'test.c', r'''
      #include <stdio.h>
      int main() {
        printf("hello, world!\n");
        return 0;
      }
      ''')
        cache_dir_name = self.in_dir('test_cache')
        libname = Cache.get_lib_name('libc.a')
        with env_modify({'EM_CACHE': cache_dir_name}):
            tasks = []
            num_times_libc_was_built = 0
            for i in range(3):
                p = self.run_process(
                    [EMCC, 'test.c', '-o', '%d.js' % i],
                    stderr=STDOUT,
                    stdout=PIPE)
                tasks += [p]
            for p in tasks:
                print('stdout:\n', p.stdout)
                if 'generating system library: ' + libname in p.stdout:
                    num_times_libc_was_built += 1

        # The cache directory must exist after the build
        self.assertExists(cache_dir_name)
        # The cache directory must contain a built libc
        self.assertExists(os.path.join(cache_dir_name, libname))
        # Exactly one child process should have triggered libc build!
        self.assertEqual(num_times_libc_was_built, 1)
Beispiel #2
0
  def test_emcc_caching(self):
    BUILDING_MESSAGE = 'generating system library: %s'

    restore_and_set_up()
    self.clear_cache()

    # Building a file that *does* need something *should* trigger cache
    # generation, but only the first time
    libname = Cache.get_lib_name('libc++.a')
    for i in range(3):
      print(i)
      self.clear()
      output = self.do([EMCC, '-O' + str(i), path_from_root('tests', 'hello_libcxx.cpp'), '-s', 'DISABLE_EXCEPTION_CATCHING=0'])
      print('\n\n\n', output)
      self.assertContainedIf(BUILDING_MESSAGE % libname, output, i == 0)
      self.assertContained('hello, world!', self.run_js('a.out.js'))
      self.assertExists(Cache.dirname)
      self.assertExists(os.path.join(Cache.dirname, libname))