Coverage for tests/test_config.py: 97%

78 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2026-05-07 14:30 +0000

1import unittest 

2from contextlib import closing 

3 

4from wasmtime import * 

5 

6 

7class TestConfig(unittest.TestCase): 

8 def test_smoke(self): 

9 config = Config() 

10 config.debug_info = True 

11 config.wasm_threads = True 

12 config.wasm_tail_call = True 

13 config.wasm_reference_types = True 

14 config.wasm_simd = True 

15 config.wasm_bulk_memory = True 

16 config.wasm_multi_value = True 

17 config.wasm_multi_memory = True 

18 config.wasm_memory64 = True 

19 config.wasm_exceptions = True 

20 config.wasm_component_model = True 

21 config.wasm_component_model_map = True 

22 config.wasm_function_references = True 

23 config.wasm_wide_arithmetic = True 

24 config.wasm_custom_page_sizes = True 

25 config.wasm_gc = True 

26 config.wasm_stack_switching = True 

27 config.wasm_relaxed_simd = True 

28 config.wasm_relaxed_simd_deterministic = True 

29 

30 config.strategy = "cranelift" 

31 config.strategy = "auto" 

32 config.cache = True 

33 config.parallel_compilation = False 

34 with self.assertRaises(WasmtimeError): 

35 config.cache = "./test.toml" 

36 with self.assertRaises(WasmtimeError): 

37 config.strategy = "nonexistent-strategy" 

38 config.cranelift_opt_level = "none" 

39 config.cranelift_opt_level = "speed_and_size" 

40 config.cranelift_opt_level = "speed" 

41 with self.assertRaises(WasmtimeError): 

42 config.cranelift_opt_level = "nonexistent-level" 

43 config.profiler = "none" 

44 config.profiler = "jitdump" 

45 config.profiler = "vtune" 

46 config.profiler = "perfmap" 

47 with self.assertRaises(WasmtimeError): 

48 config.profiler = "nonexistent-profiler" 

49 

50 config.cranelift_debug_verifier = True 

51 config.cranelift_nan_canonicalization = True 

52 config.cranelift_flag_enable("preserve_frame_pointers") 

53 config.cranelift_flag_set("opt_level", "speed") 

54 

55 config.consume_fuel = True 

56 config.max_wasm_stack = 1024 * 1024 

57 config.gc_support = True 

58 config.native_unwind_info = True 

59 config.macos_use_mach_ports = True 

60 config.signals_based_traps = True 

61 

62 config.memory_may_move = True 

63 config.memory_reservation = 1 << 20 

64 config.memory_guard_size = 1 << 16 

65 config.memory_reservation_for_growth = 1 << 20 

66 config.memory_init_cow = True 

67 

68 def test_target(self): 

69 config = Config() 

70 # Setting the host target should always succeed 

71 import platform 

72 host_triple = None 

73 if platform.machine() == "x86_64" and platform.system() == "Linux": 

74 host_triple = "x86_64-unknown-linux-gnu" 

75 elif platform.machine() == "aarch64" and platform.system() == "Linux": 

76 host_triple = "aarch64-unknown-linux-gnu" 

77 if host_triple is not None: 

78 config.target = host_triple 

79 # An invalid target should raise 

80 with self.assertRaises(WasmtimeError): 

81 config.target = "not-a-real-target" 

82 

83 with closing(config) as config: 

84 pass 

85 

86 config.close() 

87 

88 with self.assertRaises(ValueError): 

89 Engine(config) 

90 

91 with self.assertRaises(ValueError): 

92 config.cache = True