Skip to content

Commit

Permalink
[JS-to-C++ test] Test crash with active PC/SC client
Browse files Browse the repository at this point in the history
Test that a C++ crash in the executable module gets correctly
handled in case there's an active PC/SC client. The module and the
client should get disposed of without any unexpected exceptions.

This is a regression test for #823.
  • Loading branch information
emaxx-google committed Sep 14, 2023
1 parent f5b01bb commit 0a8fbfa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions smart_card_connector_app/build/js_to_cxx_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SOURCE_DIR := $(ROOT_PATH)/smart_card_connector_app/src/
# targets (for ../executable_module/cpp_unittests/). Get rid of duplicate
# compilation by putting them into static libraries.
CXX_SOURCES := \
$(ROOT_PATH)/common/cpp/src/logging_integration_test_helper.cc \
$(SOURCE_DIR)/application_integration_test_helper.cc \
$(SOURCE_DIR)/testing_smart_card_simulation.cc \

Expand Down
22 changes: 22 additions & 0 deletions smart_card_connector_app/src/pcsc-api-jstocxxtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,28 @@ goog.exportSymbol('testPcscApi', {
assert(called);
assertEquals(result.getErrorCode(), API.SCARD_E_INVALID_HANDLE);
},

// Test that no unexpected exceptions occur when the C++ module is crashing
// while there's a connected PC/SC client.
'testCrashWithActiveClient': async function() {
const BAD_CONTEXT = 123;
await testController.setUpCppHelper(
'LoggingTestHelper', /*helperArgument=*/ {});
await launchPcscServer(/*initialDevices=*/[]);
// Make a random call, to make sure all lazily created per-client state
// gets initialized.
await client.api.SCardIsValidContext(BAD_CONTEXT);

// Trigger the C++ module crash.
try {
await testController.sendMessageToCppHelper(
'LoggingTestHelper', 'crash-via-check');
} catch (e) {
// This is expected branch - discard the exception.
}

assert(client.clientHandler.isDisposed());
},
},

// Test that the PC/SC server can shut down successfully when there's an
Expand Down

0 comments on commit 0a8fbfa

Please sign in to comment.