test_pal.py 23 KB

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