test_pal.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #!/usr/bin/env python3
  2. import ast
  3. import collections
  4. import mmap
  5. import os
  6. import pathlib
  7. import random
  8. import shutil
  9. import string
  10. import subprocess
  11. import unittest
  12. from regression import (
  13. HAS_SGX,
  14. RegressionTestCase,
  15. SandboxTestCase,
  16. expectedFailureIf,
  17. )
  18. CPUINFO_FLAGS_WHITELIST = [
  19. 'fpu', 'vme', 'de', 'pse', 'tsc', 'msr', 'pae', 'mce', 'cx8', 'apic', 'sep',
  20. 'mtrr', 'pge', 'mca', 'cmov', 'pat', 'pse36', 'pn', 'clflush', 'dts',
  21. 'acpi', 'mmx', 'fxsr', 'sse', 'sse2', 'ss', 'ht', 'tm', 'ia64', 'pbe',
  22. ]
  23. class TC_00_AtomicMath(RegressionTestCase):
  24. def test_000_atomic_math(self):
  25. stdout, stderr = self.run_binary(['AtomicMath'])
  26. self.assertIn('Subtract INT_MIN: Both values match 2147483648', stderr)
  27. self.assertIn('Subtract INT_MAX: Both values match -2147483647', stderr)
  28. self.assertIn('Subtract LLONG_MIN: Both values match -9223372036854775808', stderr)
  29. self.assertIn('Subtract LLONG_MAX: Both values match -9223372036854775807', stderr)
  30. class TC_01_Bootstrap(RegressionTestCase):
  31. def test_100_basic_boostrapping(self):
  32. stdout, stderr = self.run_binary(['Bootstrap'])
  33. # Basic Bootstrapping
  34. self.assertIn('User Program Started', stderr)
  35. # Control Block: Executable Name
  36. self.assertIn('Loaded Executable: file:Bootstrap', stderr)
  37. # One Argument Given
  38. self.assertIn('# of Arguments: 1', stderr)
  39. self.assertIn('argv[0] = file:Bootstrap', stderr)
  40. # Control Block: Debug Stream (Inline)
  41. self.assertIn('Written to Debug Stream', stdout)
  42. # Control Block: Page Size
  43. self.assertIn('Page Size: {}'.format(mmap.PAGESIZE), stderr)
  44. # Control Block: Allocation Alignment
  45. self.assertIn('Allocation Alignment: {}'.format(mmap.ALLOCATIONGRANULARITY), stderr)
  46. # Control Block: Executable Range
  47. self.assertIn('Executable Range OK', stderr)
  48. def test_101_basic_boostrapping_five_arguments(self):
  49. stdout, stderr = self.run_binary(['Bootstrap', 'a', 'b', 'c', 'd'])
  50. # Five Arguments Given
  51. self.assertIn('# of Arguments: 5', stderr)
  52. self.assertIn('argv[1] = a', stderr)
  53. self.assertIn('argv[2] = b', stderr)
  54. self.assertIn('argv[3] = c', stderr)
  55. self.assertIn('argv[4] = d', stderr)
  56. def test_102_cpuinfo(self):
  57. with open('/proc/cpuinfo') as file:
  58. cpuinfo = file.read().strip().split('\n\n')[-1]
  59. cpuinfo = dict(map(str.strip, line.split(':'))
  60. for line in cpuinfo.split('\n'))
  61. if 'flags' in cpuinfo:
  62. cpuinfo['flags'] = ' '.join(flag for flag in cpuinfo['flags']
  63. if flag in CPUINFO_FLAGS_WHITELIST)
  64. stdout, stderr = self.run_binary(['Bootstrap'])
  65. self.assertIn('CPU num: {}'.format(int(cpuinfo['processor']) + 1),
  66. stderr)
  67. self.assertIn('CPU vendor: {[vendor_id]}'.format(cpuinfo), stderr)
  68. self.assertIn('CPU brand: {[model name]}'.format(cpuinfo), stderr)
  69. self.assertIn('CPU family: {[cpu family]}'.format(cpuinfo), stderr)
  70. self.assertIn('CPU model: {[model]}'.format(cpuinfo), stderr)
  71. self.assertIn('CPU stepping: {[stepping]}'.format(cpuinfo), stderr)
  72. self.assertIn('CPU flags: {[flags]}'.format(cpuinfo), stderr)
  73. def test_103_dotdot(self):
  74. stdout, stderr = self.run_binary(['..Bootstrap'])
  75. self.assertIn('User Program Started', stderr)
  76. def test_104_manifest_as_executable_name(self):
  77. manifest = self.get_manifest('Bootstrap2')
  78. stdout, stderr = self.run_binary([manifest])
  79. self.assertIn('User Program Started', stderr)
  80. self.assertIn('Loaded Manifest: file:' + manifest, stderr)
  81. def test_105_manifest_as_argument(self):
  82. manifest = self.get_manifest('Bootstrap4')
  83. stdout, stderr = self.run_binary([manifest])
  84. self.assertIn('Loaded Manifest: file:' + manifest, stderr)
  85. self.assertIn('Loaded Executable: file:Bootstrap', stderr)
  86. def test_106_manifest_with_shebang(self):
  87. manifest = self.get_manifest('Bootstrap4')
  88. stdout, stderr = self.run_binary(['./' + manifest])
  89. self.assertIn('Loaded Manifest: file:' + manifest, stderr)
  90. self.assertIn('Loaded Executable: file:Bootstrap', stderr)
  91. self.assertIn('argv[0] = Bootstrap', stderr)
  92. def test_110_preload_libraries(self):
  93. stdout, stderr = self.run_binary(['Bootstrap3'])
  94. self.assertIn('Binary 1 Preloaded', stderr)
  95. self.assertIn('Binary 2 Preloaded', stderr)
  96. self.assertIn('Preloaded Function 1 Called', stderr)
  97. self.assertIn('Preloaded Function 2 Called', stderr)
  98. def test_111_preload_libraries(self):
  99. # Bootstrap without Executable but Preload Libraries
  100. stdout, stderr = self.run_binary([self.get_manifest('Bootstrap5')])
  101. self.assertIn('Binary 1 Preloaded', stderr)
  102. self.assertIn('Binary 2 Preloaded', stderr)
  103. @unittest.skipUnless(HAS_SGX, 'this test requires SGX')
  104. def test_120_8gb_enclave(self):
  105. manifest = self.get_manifest('Bootstrap6')
  106. stdout, stderr = self.run_binary([manifest], timeout=240)
  107. self.assertIn('Loaded Manifest: file:' + manifest, stderr)
  108. self.assertIn('Executable Range OK', stderr)
  109. def test_130_large_number_of_items_in_manifest(self):
  110. stdout, stderr = self.run_binary([self.get_manifest('Bootstrap7')])
  111. self.assertIn('key1000=na', stderr)
  112. self.assertIn('key1=na', stderr)
  113. @unittest.skip('this is broken on non-SGX, see #860')
  114. def test_140_missing_executable_and_manifest(self):
  115. try:
  116. stdout, stderr = self.run_binary(['fakenews'])
  117. self.fail(
  118. 'expected non-zero returncode, stderr: {!r}'.format(stderr))
  119. except subprocess.CalledProcessError as e:
  120. self.assertIn('USAGE: ', e.stderr.decode())
  121. class TC_02_Symbols(RegressionTestCase):
  122. ALL_SYMBOLS = [
  123. 'DkVirtualMemoryAlloc',
  124. 'DkVirtualMemoryFree',
  125. 'DkVirtualMemoryProtect',
  126. 'DkProcessCreate',
  127. 'DkProcessExit',
  128. 'DkProcessSandboxCreate',
  129. 'DkStreamOpen',
  130. 'DkStreamWaitForClient',
  131. 'DkStreamRead',
  132. 'DkStreamWrite',
  133. 'DkStreamDelete',
  134. 'DkStreamMap',
  135. 'DkStreamUnmap',
  136. 'DkStreamSetLength',
  137. 'DkStreamFlush',
  138. 'DkSendHandle',
  139. 'DkReceiveHandle',
  140. 'DkStreamAttributesQuery',
  141. 'DkStreamAttributesQueryByHandle',
  142. 'DkStreamAttributesSetByHandle',
  143. 'DkStreamGetName',
  144. 'DkStreamChangeName',
  145. 'DkThreadCreate',
  146. 'DkThreadDelayExecution',
  147. 'DkThreadYieldExecution',
  148. 'DkThreadExit',
  149. 'DkThreadResume',
  150. 'DkSetExceptionHandler',
  151. 'DkExceptionReturn',
  152. 'DkMutexCreate',
  153. 'DkMutexRelease',
  154. 'DkNotificationEventCreate',
  155. 'DkSynchronizationEventCreate',
  156. 'DkEventSet',
  157. 'DkEventClear',
  158. 'DkObjectsWaitAny',
  159. 'DkObjectClose',
  160. 'DkSystemTimeQuery',
  161. 'DkRandomBitsRead',
  162. 'DkInstructionCacheFlush',
  163. 'DkSegmentRegister',
  164. 'DkMemoryAvailableQuota',
  165. 'DkCreatePhysicalMemoryChannel',
  166. 'DkPhysicalMemoryCommit',
  167. 'DkPhysicalMemoryMap',
  168. ]
  169. def test_000_symbols(self):
  170. stdout, stderr = self.run_binary(['Symbols'])
  171. found_symbols = dict(line.split(' = ')
  172. for line in stderr.strip().split('\n') if line.startswith('Dk'))
  173. self.assertCountEqual(found_symbols, self.ALL_SYMBOLS)
  174. for k, v in found_symbols.items():
  175. v = ast.literal_eval(v)
  176. self.assertNotEqual(v, 0, 'symbol {} has value 0'.format(k))
  177. class TC_10_Exception(RegressionTestCase):
  178. def test_000_exception(self):
  179. stdout, stderr = self.run_binary(['Exception'])
  180. # Exception Handling (Div-by-Zero)
  181. self.assertIn('Arithmetic Exception Handler', stderr)
  182. # Exception Handling (Memory Fault)
  183. self.assertIn('Memory Fault Exception Handler', stderr)
  184. # Exception Handler Swap
  185. self.assertIn('Arithmetic Exception Handler 1', stderr)
  186. self.assertIn('Arithmetic Exception Handler 2', stderr)
  187. # Exception Handling (Set Context)
  188. self.assertIn('Arithmetic Exception Handler 1', stderr)
  189. # Exception Handling (Red zone)
  190. self.assertIn('Red zone test ok.', stderr)
  191. class TC_20_SingleProcess(RegressionTestCase):
  192. def test_000_exit_code(self):
  193. with self.expect_returncode(112):
  194. self.run_binary(['Exit'])
  195. def test_100_file(self):
  196. try:
  197. pathlib.Path('file_nonexist.tmp').unlink()
  198. except FileNotFoundError:
  199. pass
  200. pathlib.Path('file_delete.tmp').touch()
  201. with open('File', 'rb') as file:
  202. file_exist = file.read()
  203. stdout, stderr = self.run_binary(['File'])
  204. # Basic File Opening
  205. self.assertIn('File Open Test 1 OK', stderr)
  206. self.assertIn('File Open Test 2 OK', stderr)
  207. self.assertIn('File Open Test 3 OK', stderr)
  208. # Basic File Creation
  209. self.assertIn('File Creation Test 1 OK', stderr)
  210. self.assertIn('File Creation Test 2 OK', stderr)
  211. self.assertIn('File Creation Test 3 OK', stderr)
  212. # File Reading
  213. self.assertIn('Read Test 1 (0th - 40th): {}'.format(
  214. file_exist[0:40].hex()), stderr)
  215. self.assertIn('Read Test 2 (0th - 40th): {}'.format(
  216. file_exist[0:40].hex()), stderr)
  217. self.assertIn('Read Test 3 (200th - 240th): {}'.format(
  218. file_exist[200:240].hex()), stderr)
  219. # File Writing
  220. with open('file_nonexist.tmp', 'rb') as file:
  221. file_nonexist = file.read()
  222. self.assertEqual(file_exist[0:40], file_nonexist[200:240])
  223. self.assertEqual(file_exist[200:240], file_nonexist[0:40])
  224. # File Attribute Query
  225. self.assertIn(
  226. 'Query: type = 1, size = {}'.format(len(file_exist)), stderr)
  227. # File Attribute Query by Handle
  228. self.assertIn(
  229. 'Query by Handle: type = 1, size = {}'.format(len(file_exist)),
  230. stderr)
  231. # File Mapping
  232. self.assertIn(
  233. 'Map Test 1 (0th - 40th): {}'.format(file_exist[0:40].hex()),
  234. stderr)
  235. self.assertIn(
  236. 'Map Test 2 (200th - 240th): {}'.format(file_exist[200:240].hex()),
  237. stderr)
  238. self.assertIn(
  239. 'Map Test 3 (4096th - 4136th): {}'.format(file_exist[4096:4136].hex()),
  240. stderr)
  241. self.assertIn(
  242. 'Map Test 4 (4296th - 4336th): {}'.format(file_exist[4296:4336].hex()),
  243. stderr)
  244. # Set File Length
  245. self.assertEqual(
  246. pathlib.Path('file_nonexist.tmp').stat().st_size,
  247. mmap.ALLOCATIONGRANULARITY)
  248. # File Deletion
  249. self.assertFalse(pathlib.Path('file_delete.tmp').exists())
  250. def test_110_directory(self):
  251. for path in ['dir_exist.tmp', 'dir_nonexist.tmp', 'dir_delete.tmp']:
  252. try:
  253. shutil.rmtree(path)
  254. except FileNotFoundError:
  255. pass
  256. path = pathlib.Path('dir_exist.tmp')
  257. files = [path / ''.join(random.choice(string.ascii_letters)
  258. for j in range(8))
  259. for i in range(5)]
  260. path.mkdir()
  261. for p in files:
  262. p.touch()
  263. pathlib.Path('dir_delete.tmp').mkdir()
  264. stdout, stderr = self.run_binary(['Directory'])
  265. # Basic Directory Opening
  266. self.assertIn('Directory Open Test 1 OK', stderr)
  267. self.assertIn('Directory Open Test 2 OK', stderr)
  268. self.assertIn('Directory Open Test 3 OK', stderr)
  269. # Basic Directory Creation
  270. self.assertIn('Directory Creation Test 1 OK', stderr)
  271. self.assertIn('Directory Creation Test 2 OK', stderr)
  272. self.assertIn('Directory Creation Test 3 OK', stderr)
  273. # Directory Reading
  274. for p in files:
  275. self.assertIn('Read Directory: {}'.format(p.name), stderr)
  276. # Directory Attribute Query
  277. self.assertIn('Query: type = 7', stderr)
  278. # Directory Attribute Query by Handle
  279. self.assertIn('Query by Handle: type = 7', stderr)
  280. # Directory Deletion
  281. self.assertFalse(pathlib.Path('dir_delete.tmp').exists())
  282. def test_200_event(self):
  283. stdout, stderr = self.run_binary(['Event'])
  284. self.assertIn('Wait with too short timeout ok.', stderr)
  285. self.assertIn('Wait with long enough timeout ok.', stderr)
  286. def test_210_semaphore(self):
  287. stdout, stderr = self.run_binary(['Semaphore'])
  288. # Semaphore: Timeout on Locked Semaphores
  289. self.assertIn('Locked binary semaphore timed out (1000).', stderr)
  290. self.assertIn('Locked binary semaphore timed out (0).', stderr)
  291. # Semaphore: Acquire Unlocked Semaphores
  292. self.assertIn('Locked binary semaphore successfully (-1).', stderr)
  293. self.assertIn('Locked binary semaphore successfully (0).', stderr)
  294. def test_300_memory(self):
  295. stdout, stderr = self.run_binary(['Memory'])
  296. # Memory Allocation
  297. self.assertIn('Memory Allocation OK', stderr)
  298. # Memory Allocation with Address
  299. self.assertIn('Memory Allocation with Address OK', stderr)
  300. # Get Memory Total Quota
  301. self.assertIn('Total Memory:', stderr)
  302. for line in stderr.split('\n'):
  303. if line.startswith('Total Memory:'):
  304. self.assertNotEqual(line, 'Total Memory: 0')
  305. # Get Memory Available Quota
  306. self.assertIn('Get Memory Available Quota OK', stderr)
  307. @expectedFailureIf(HAS_SGX)
  308. def test_301_memory_nosgx(self):
  309. stdout, stderr = self.run_binary(['Memory'])
  310. # SGX1 does not support unmapping a page or changing its permission
  311. # after enclave init. Therefore the memory protection and deallocation
  312. # tests will fail. By utilizing SGX2 it's possibile to fix this.
  313. # Memory Protection
  314. self.assertIn('Memory Allocation Protection (RW) OK', stderr)
  315. self.assertIn('Memory Protection (R) OK', stderr)
  316. # Memory Deallocation
  317. self.assertIn('Memory Deallocation OK', stderr)
  318. def test_400_pipe(self):
  319. stdout, stderr = self.run_binary(['Pipe'])
  320. # Pipe Creation
  321. self.assertIn('Pipe Creation 1 OK', stderr)
  322. # Pipe Attributes
  323. self.assertIn('Pipe Attribute Query 1 on pipesrv returned OK', stderr)
  324. # Pipe Connection
  325. self.assertIn('Pipe Connection 1 OK', stderr)
  326. # Pipe Transmission
  327. self.assertIn('Pipe Write 1 OK', stderr)
  328. self.assertIn('Pipe Read 1: Hello World 1', stderr)
  329. self.assertIn('Pipe Write 2 OK', stderr)
  330. self.assertIn('Pipe Read 2: Hello World 2', stderr)
  331. def test_410_socket(self):
  332. stdout, stderr = self.run_binary(['Socket'])
  333. # TCP Socket Creation
  334. self.assertIn('TCP Creation 1 OK', stderr)
  335. # TCP Socket Connection
  336. self.assertIn('TCP Connection 1 OK', stderr)
  337. # TCP Socket Transmission
  338. self.assertIn('TCP Write 1 OK', stderr)
  339. self.assertIn('TCP Read 1: Hello World 1', stderr)
  340. self.assertIn('TCP Write 2 OK', stderr)
  341. self.assertIn('TCP Read 2: Hello World 2', stderr)
  342. # UDP Socket Creation
  343. self.assertIn('UDP Creation 1 OK', stderr)
  344. # UDP Socket Connection
  345. self.assertIn('UDP Connection 1 OK', stderr)
  346. # UDP Socket Transmission
  347. self.assertIn('UDP Write 1 OK', stderr)
  348. self.assertIn('UDP Read 1: Hello World 1', stderr)
  349. self.assertIn('UDP Write 2 OK', stderr)
  350. self.assertIn('UDP Read 2: Hello World 2', stderr)
  351. # Bound UDP Socket Transmission
  352. self.assertIn('UDP Write 3 OK', stderr)
  353. self.assertIn('UDP Read 3: Hello World 1', stderr)
  354. self.assertIn('UDP Write 4 OK', stderr)
  355. self.assertIn('UDP Read 4: Hello World 2', stderr)
  356. def test_500_thread(self):
  357. stdout, stderr = self.run_binary(['Thread'])
  358. # Thread Creation
  359. self.assertIn('Child Thread Created', stderr)
  360. self.assertIn('Run in Child Thread: Hello World', stderr)
  361. # Multiple Threads Run in Parallel
  362. self.assertIn('Threads Run in Parallel OK', stderr)
  363. # Set Thread Private Segment Register
  364. self.assertIn('Private Message (FS Segment) 1: Hello World 1', stderr)
  365. self.assertIn('Private Message (FS Segment) 2: Hello World 2', stderr)
  366. # Thread Exit
  367. self.assertIn('Child Thread Exited', stderr)
  368. def test_510_thread2(self):
  369. stdout, stderr = self.run_binary(['Thread2'])
  370. # Thread Cleanup: Exit by return.
  371. self.assertIn('Thread 2 ok.', stderr)
  372. @expectedFailureIf(HAS_SGX)
  373. def test_511_thread2_nosgx(self):
  374. stdout, stderr = self.run_binary(['Thread2'])
  375. # The 2 following tests are currently broken on SGX because TCS slots
  376. # are not reused yet (needed because of thread limit), see issue #517.
  377. # Thread Cleanup: Exit by DkThreadExit.
  378. self.assertIn('Thread 3 ok.', stderr)
  379. self.assertNotIn('Exiting thread 3 failed.', stderr)
  380. # Thread Cleanup: Can still start threads.
  381. self.assertIn('Thread 4 ok.', stderr)
  382. def test_900_misc(self):
  383. stdout, stderr = self.run_binary(['Misc'])
  384. # Query System Time
  385. self.assertIn('Query System Time OK', stderr)
  386. # Delay Execution for 10000 Microseconds
  387. self.assertIn('Delay Execution for 10000 Microseconds OK', stderr)
  388. # Delay Execution for 3 Seconds
  389. self.assertIn('Delay Execution for 3 Seconds OK', stderr)
  390. # Generate Random Bits
  391. self.assertIn('Generate Random Bits OK', stderr)
  392. def test_910_hex(self):
  393. stdout, stderr = self.run_binary(['Hex'])
  394. # Hex 2 String Helper Function
  395. self.assertIn('Hex test 1 is deadbeef', stderr)
  396. self.assertIn('Hex test 2 is cdcdcdcdcdcdcdcd', stderr)
  397. class TC_21_ProcessCreation(RegressionTestCase):
  398. def test_100_process(self):
  399. stdout, stderr = self.run_binary(['Process'], timeout=8)
  400. counter = collections.Counter(stderr.split('\n'))
  401. # Process Creation
  402. self.assertEqual(counter['Child Process Created'], 3)
  403. # Process Creation Arguments
  404. self.assertEqual(counter['argv[0] = Process'], 3)
  405. self.assertEqual(counter['argv[1] = Child'], 3)
  406. # Process Channel Transmission
  407. self.assertEqual(counter['Process Write 1 OK'], 3)
  408. self.assertEqual(counter['Process Read 1: Hello World 1'], 3)
  409. self.assertEqual(counter['Process Write 2 OK'], 3)
  410. self.assertEqual(counter['Process Read 2: Hello World 2'], 3)
  411. def test_110_process_broadcast(self):
  412. stdout, stderr = self.run_binary(['Process'], timeout=8)
  413. counter = collections.Counter(stderr.split('\n'))
  414. # Multi-Process Broadcast Channel Transmission
  415. if ('Warning: broadcast stream is not open. '
  416. 'Do you have a multicast route configured?') in stderr:
  417. self.skipTest('Could not open broadcast stream. '
  418. 'Do you have a multicast route configured?')
  419. self.assertEqual(counter['Broadcast Write OK'], 1)
  420. self.assertEqual(counter['Broadcast Read: Hello World 1'], 3)
  421. def test_200_process2(self):
  422. # Process Creation with a Different Binary
  423. stdout, stderr = self.run_binary(['Process2'])
  424. counter = collections.Counter(stderr.split('\n'))
  425. self.assertEqual(counter['User Program Started'], 1)
  426. def test_300_process3(self):
  427. # Process Creation without Executable
  428. stdout, stderr = self.run_binary(['Process3'])
  429. counter = collections.Counter(stderr.split('\n'))
  430. self.assertEqual(counter['Binary 1 Preloaded'], 2)
  431. self.assertEqual(counter['Binary 2 Preloaded'], 2)
  432. @unittest.skipIf(HAS_SGX, 'GIPC not supported on SGX')
  433. ## XXX Should really be running these tests as part of CI
  434. @unittest.skipUnless(pathlib.Path('/dev/gipc').exists(), 'GIPC not loaded')
  435. class TC_22_GIPC(RegressionTestCase):
  436. def test_000_gipc(self):
  437. with open('ipc_mapping.tmp', 'w') as file:
  438. file.write('Hello World')
  439. os.ftruncate(file.fileno(), mmap.PAGESIZE)
  440. stdout, stderr = self.run_binary(['Ipc'])
  441. counter = collections.Counter(stderr.split('\n'))
  442. # Create and Join Physical Memory Bulk Copy Store
  443. self.assertEqual(counter['Create Physical Memory Store OK'], 5)
  444. self.assertEqual(counter['Join Physical Memory Store OK'], 5)
  445. # Map and Commit Anonymous Physical Memory
  446. self.assertIn('[Test 1] Physical Memory Commit OK', stderr)
  447. self.assertIn('[Test 1] Physical Memory Map : Hello World', stderr)
  448. # Transfer Anonymous Physical Memory as Copy-on-Write
  449. self.assertIn('[Test 1] Sender After Commit: Hello World, Alice', stderr)
  450. self.assertIn('[Test 1] Sender Before Map : Alice, Hello World', stderr)
  451. self.assertIn('[Test 1] Receiver After Map : Hello World, Bob', stderr)
  452. self.assertIn('[Test 1] Sender After Map : Alice, Hello World', stderr)
  453. # Map and Commit Untouched Physical Memory
  454. self.assertIn('[Test 2] Physical Memory Commit OK', stderr)
  455. self.assertIn('[Test 2] Physical Memory Map : ', stderr)
  456. self.assertIn('[Test 2] Sender After Commit: Hello World, Alice', stderr)
  457. self.assertIn('[Test 2] Sender Before Map : Alice, Hello World', stderr)
  458. self.assertIn('[Test 2] Receiver After Map : Hello World, Bob', stderr)
  459. self.assertIn('[Test 2] Sender After Map : Alice, Hello World', stderr)
  460. # Map and Commit File-Backed Physical Memory
  461. self.assertIn('[Test 3] Physical Memory Commit OK', stderr)
  462. self.assertIn('[Test 3] Physical Memory Map : Hello World', stderr)
  463. self.assertIn('[Test 3] Sender After Commit: Hello World', stderr)
  464. self.assertIn('[Test 3] Receiver After Map : Hello World, Bob', stderr)
  465. self.assertIn('[Test 3] Sender After Map : Hello World', stderr)
  466. # Map and Commit File-Backed Physical Memory Beyond File Size
  467. self.assertIn('[Test 4] Physical Memory Commit OK', stderr)
  468. self.assertIn('[Test 4] Physical Memory Map : Memory Fault', stderr)
  469. # Map and Commit Huge Physical Memory
  470. self.assertIn('[Test 5] Physical Memory Commit OK', stderr)
  471. self.assertIn('[Test 5] Physical Memory Map : Hello World', stderr)
  472. class TC_23_SendHandle(RegressionTestCase):
  473. def test_000_send_handle(self):
  474. stdout, stderr = self.run_binary(['SendHandle'])
  475. counter = collections.Counter(stderr.split('\n'))
  476. # Send and Receive Handles across Processes
  477. self.assertEqual(counter['Send Handle OK'], 3)
  478. self.assertEqual(counter['Receive Handle OK'], 3)
  479. # Send Pipe Handle
  480. self.assertEqual(counter['Receive Pipe Handle: Hello World'], 1)
  481. # Send Socket Handle
  482. self.assertEqual(counter['Receive Socket Handle: Hello World'], 1)
  483. # Send File Handle
  484. self.assertEqual(counter['Receive File Handle: Hello World'], 1)
  485. @unittest.expectedFailure
  486. class TC_30_Sandbox_Bootstrap(SandboxTestCase, TC_01_Bootstrap):
  487. pass
  488. @unittest.expectedFailure
  489. class TC_31_Sandbox_Process(SandboxTestCase, TC_21_ProcessCreation):
  490. pass
  491. @unittest.skipUnless(HAS_SGX, 'need SGX')
  492. class TC_40_AVXDisable(RegressionTestCase):
  493. @unittest.expectedFailure
  494. def test_000_avx_disable(self):
  495. # Disable AVX bit in XFRM
  496. stdout, stderr = self.run_binary(['AvxDisable'])
  497. self.assertIn('Illegal instruction executed in enclave', stderr)