test_pal.py 23 KB

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