test_pal.py 21 KB

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