Skip to content

Commit 794baeb

Browse files
authored
Add a crashy program for SetString test. (#4443)
b/358663298 Change-Id: If8931dac92837bc7295006e7c3e57fe8f91dc627
1 parent 9423400 commit 794baeb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

starboard/extension/BUILD.gn

+10
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ target(gtest_target_type, "extension_test") {
2929
deps += cobalt_platform_dependencies
3030
}
3131
}
32+
33+
target(gtest_target_type, "setstring_test") {
34+
testonly = true
35+
has_pedantic_warnings = true
36+
sources = [ "setstring_test.cc" ]
37+
deps = [ "//testing/gtest" ]
38+
if (sb_is_modular && current_toolchain == cobalt_toolchain) {
39+
deps += cobalt_platform_dependencies
40+
}
41+
}

starboard/extension/setstring_test.cc

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This is a kind of death test, as described in
16+
// https://github.com/google/googletest/blob/main/docs/advanced.md#death-tests,
17+
// except, it doesn't spawn another process, but terminates itself.
18+
// It is intended to be started from a host machine on a target device
19+
// to generate a coredump, which is manually verified on the host.
20+
21+
#include "starboard/client_porting/wrap_main/wrap_main.h"
22+
#include "starboard/event.h"
23+
#include "starboard/extension/crash_handler.h"
24+
#include "starboard/system.h"
25+
#include "testing/gtest/include/gtest/gtest.h"
26+
27+
const char* test_string = "TestString";
28+
29+
TEST(ExtensionTest, MANUAL_SetString) {
30+
typedef CobaltExtensionCrashHandlerApi ExtensionApi;
31+
32+
const ExtensionApi* extension_api = static_cast<const ExtensionApi*>(
33+
SbSystemGetExtension(kCobaltExtensionCrashHandlerName));
34+
if (!extension_api) {
35+
return;
36+
}
37+
38+
extension_api->SetString("Annotation1", test_string);
39+
extension_api->SetString("Annotation2", test_string);
40+
extension_api->SetString("Annotation3", test_string);
41+
extension_api->SetString("Annotation4", test_string);
42+
43+
SbSystemBreakIntoDebugger();
44+
}
45+
46+
namespace {
47+
int InitAndRunAllTests(int argc, char** argv) {
48+
::testing::InitGoogleTest(&argc, argv);
49+
return RUN_ALL_TESTS();
50+
}
51+
} // namespace
52+
53+
// When we are building Evergreen we need to export SbEventHandle so that the
54+
// ELF loader can find and invoke it.
55+
#if SB_IS(MODULAR)
56+
SB_EXPORT
57+
#endif // SB_IS(MODULAR)
58+
STARBOARD_WRAP_SIMPLE_MAIN(InitAndRunAllTests);

0 commit comments

Comments
 (0)