Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test threadcxx to test std::thread functionality in the enclave #612

Merged
merged 0 commits into from
Sep 5, 2018

Conversation

anitagov
Copy link
Contributor

@anitagov anitagov commented Aug 29, 2018

New test threadcxx to excercise C++11 synchronization primitives using std::thread in enclaves. This was necessary as the OE thread APIs are now private. (Issue #476 )
Test was enhanced to use C++ RAII paradigm to benefit from the exception-safe resource management and avoid deadlocks/starvation seen with multi-threading.

@anitagov
Copy link
Contributor Author

Anand/Mike/Simon: This is ready for your review. Thanks.

Copy link
Contributor

@anakrish anakrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work.
On the whole looks good.
Few comments.

tests/threadcxx/args.h Outdated Show resolved Hide resolved
tests/threadcxx/args.h Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/enc.cpp Show resolved Hide resolved
tests/threadcxx/enc/enc.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/enc.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/enc.cpp Outdated Show resolved Hide resolved
OE_TEST(
oe_call_enclave(enclave, "WaitForExclusiveAccessCxx", NULL) ==
OE_OK);
// std::this_thread::sleep_for(std::chrono::microseconds(30 * 1000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove is not needed?
Does the test work if this is uncommented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the test works better without the extra sleep after WaitForExclusiveAccess and RelinquishExclusiveAccess. Will fix this.

@CodeMonkeyLeet CodeMonkeyLeet added the testing Issue has to do with testing or quality management label Aug 30, 2018
@CodeMonkeyLeet CodeMonkeyLeet added this to Backlog in Public preview via automation Aug 30, 2018
@CodeMonkeyLeet CodeMonkeyLeet added this to the 2018.09 milestone Aug 30, 2018
Copy link
Contributor

@CodeMonkeyLeet CodeMonkeyLeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments and cleanup TestMutexCxx as needed.

@@ -0,0 +1,39 @@
-----BEGIN RSA PRIVATE KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid checking in new test signing keys/sign.conf and use the OE_SET_ENCLAVE_SGX macro instead unless you're explicitly testing signing. See tests\getenclave and others like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OE_SET_ENCLAVE_SGX macro does not work with cpp files. All the tests that use these are .c files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler error is:
'visibility' attribute ignored [-Werror=attributes].
With cc1plus: all warnings being treated as errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the error happens because in C++ const objects by default have internal linkage (as if the "static" keyword was added to the declaration automatically). Therefore GCC specific visibility attributes are ignored so as to be C++ conformant.

To fix the compile error, we just need to add the "export" keyword to the variable being declared via the macro:

OE_EXPORT extern const oe_sgx_enclave_properties_t oe_enclavePropertiesSGX = \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, implemented this. Thanks.

tests/threadcxx/args.h Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
oe_call_enclave(enclave, "WaitForExclusiveAccessCxx", NULL) ==
OE_OK);

OE_TEST(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was comparing this with the tests/thread implementation and noticed you took out the thread sleep here. It looks like the sleep was introduced to force threads to wait (i.e. it increases the window where a thread is causing other threads to wait) Did you find that it was unnecessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find out why the test was failing if we add the wait?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to investigate some more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeMonkeyLeet - In my case, adding the wait times causes a lib panic assert in libcxxrt_stubs.c. Debugging to see why this happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With oe-gdb, the lib panic assert never occurred as the timing of the threads is considerably changed. But able to reproduce this relatively easily using ctest -V. Will add the oe_print_backtrace new feature to get a stack trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried a test of removing these wait times in the original thread test and noticed that it never failed (ran it in 100+ times).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My CoffeeLake lab machine is down today and I am unable to reproduce the failure (when the sleep is added) on Azure VM CoffeeLake and KabyLake.

tests/threadcxx/args.h Outdated Show resolved Hide resolved
tests/threadcxx/host/host.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/enc.cpp Show resolved Hide resolved
tests/threadcxx/enc/CMakeLists.txt Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
tests/threadcxx/README.md Outdated Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
oe_call_enclave(enclave, "WaitForExclusiveAccessCxx", NULL) ==
OE_OK);

OE_TEST(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find out why the test was failing if we add the wait?

@anitagov
Copy link
Contributor Author

anitagov commented Sep 1, 2018

Addressed another round of feedback from Anand.

@CodeMonkeyLeet CodeMonkeyLeet moved this from Backlog to In review in Public preview Sep 4, 2018
@anitagov
Copy link
Contributor Author

anitagov commented Sep 5, 2018

Anand: The code has been merged with master and ready for your review. The failing case when the sleep is added in ExclusiveAccessThread is not reproducible on other machines and the lab machines are down until EOW. So, great if you can review this PR. Thanks.

Copy link
Contributor

@anakrish anakrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Please fix some formatting issues.
We can investigate the sporadic crash once we have the machines back. The issue seems to happen only on your Coffee lake machine.

tests/threadcxx/enc/cond_tests.cpp Show resolved Hide resolved
tests/threadcxx/enc/cond_tests.cpp Outdated Show resolved Hide resolved
@anitagov
Copy link
Contributor Author

anitagov commented Sep 5, 2018

Fixed the minor formatting issue and also tested in all 3 modes (Debug, Release and RelWithDebInfo) on a KabyLake VM as CI KabyLake machines are also down.
The test does not fail in its current state on any of the various machines that I tried for several hours. Adding the sleep in the ExclusiveAccessThread causes the library assert only on my CoffeeLake lab machine (which is currently down).

@anitagov anitagov merged commit 45fe2ca into master Sep 5, 2018
Public preview automation moved this from In review to Done Sep 5, 2018
@CodeMonkeyLeet CodeMonkeyLeet deleted the threadcxx-test branch September 11, 2018 19:18
johnkord pushed a commit that referenced this pull request Sep 12, 2018
…612)

* New test cthreadcxx to verify std::thread functionality in enclave

* Standardized enclave printf to std::cout

* Changed mtx to recursive_mutex

* Extended TestMutexCxx to use 2 recursive mutexes

* Changed cond_variable_any to cond_variable

* Incorporated review comments - following RA11 paradigm

* Modified enc.cpp to use condition_variable with unique_lock/lock_guard

* Using OE_SET_ENCLAVE_SGX macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Issue has to do with testing or quality management
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants