diff --git a/tests/SConstruct b/tests/SConstruct index c100a07..2b3698d 100644 --- a/tests/SConstruct +++ b/tests/SConstruct @@ -14,8 +14,10 @@ LINKFLAGS Flags to pass to linker LINKLIBS Flags to pass to linker after object files PROTOC Path to protoc binary PROTOCFLAGS Arguments to pass protoc +PLATFORM Run using simulator NODEFARGS Do not add the default CCFLAGS NOVALGRIND Do not use valgrind for memory checks +NOUNSAFE Skip tests that intentionally break memory safety For example, for a clang build, use: scons CC=clang CXX=clang++ diff --git a/tests/alltypes/decode_alltypes.c b/tests/alltypes/decode_alltypes.c index 8e70d86..008c117 100644 --- a/tests/alltypes/decode_alltypes.c +++ b/tests/alltypes/decode_alltypes.c @@ -302,9 +302,6 @@ bool check_alltypes(pb_istream_t *stream, int mode) return status == 0; } -#ifdef __cplusplus -extern "C" -#endif int main(int argc, char **argv) { uint8_t buffer[1024]; diff --git a/tests/alltypes/encode_alltypes.c b/tests/alltypes/encode_alltypes.c index 6067c54..2fcb813 100644 --- a/tests/alltypes/encode_alltypes.c +++ b/tests/alltypes/encode_alltypes.c @@ -8,9 +8,6 @@ #include "alltypes.pb.h" #include "test_helpers.h" -#ifdef __cplusplus -extern "C" -#endif int main(int argc, char **argv) { int mode = (argc > 1) ? atoi(argv[1]) : 0; diff --git a/tests/cxx_callback_datatype/cxx_callback_datatype.cpp b/tests/cxx_callback_datatype/cxx_callback_datatype.cpp index 2b06d37..e506037 100644 --- a/tests/cxx_callback_datatype/cxx_callback_datatype.cpp +++ b/tests/cxx_callback_datatype/cxx_callback_datatype.cpp @@ -44,7 +44,6 @@ bool TestMessage_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb return true; } -extern "C" int main() { TestMessage source = TestMessage_init_zero; // Not strictly necessary to initialize, just using it to test the initializer. source.values.push_back(5); diff --git a/tests/cxx_descriptor/message_descriptor.cc b/tests/cxx_descriptor/message_descriptor.cc index 149000b..f034d85 100644 --- a/tests/cxx_descriptor/message_descriptor.cc +++ b/tests/cxx_descriptor/message_descriptor.cc @@ -2,7 +2,7 @@ #include "message.pb.h" #include "unittests.h" -extern "C" int main() { +int main() { using namespace nanopb; #if __cplusplus >= 201103L diff --git a/tests/enum_sizes/enum_intsize_unittests.cc b/tests/enum_sizes/enum_intsize_unittests.cc index dae8737..e89d8f3 100644 --- a/tests/enum_sizes/enum_intsize_unittests.cc +++ b/tests/enum_sizes/enum_intsize_unittests.cc @@ -2,7 +2,7 @@ #include "enum_intsize.pb.hpp" #include "unittests.h" -extern "C" int main() +int main() { int status = 0; diff --git a/tests/namingstyle/test_cxx_descriptor.cc b/tests/namingstyle/test_cxx_descriptor.cc index ff69df3..857f115 100644 --- a/tests/namingstyle/test_cxx_descriptor.cc +++ b/tests/namingstyle/test_cxx_descriptor.cc @@ -2,7 +2,7 @@ #include "naming_style.pb.h" #include "unittests.h" -extern "C" int main() { +int main() { using namespace nanopb; int status = 0; diff --git a/tests/regression/issue_494/oneof_size.cc b/tests/regression/issue_494/oneof_size.cc index 608fd91..493166c 100644 --- a/tests/regression/issue_494/oneof_size.cc +++ b/tests/regression/issue_494/oneof_size.cc @@ -1,7 +1,7 @@ #include "oneof.pb.h" #include "unittests.h" -extern "C" int main() +int main() { int status = 0; diff --git a/tests/regression/issue_838/enum_to_string.cxx b/tests/regression/issue_838/enum_to_string.cxx index 69c4b40..d1e857a 100644 --- a/tests/regression/issue_838/enum_to_string.cxx +++ b/tests/regression/issue_838/enum_to_string.cxx @@ -2,7 +2,7 @@ #include "unittests.h" #include "enum.pb.h" -extern "C" int main() +int main() { int status = 0; TEST(strcmp(MyEnum_name(MyEnum_VALUE1), "VALUE1") == 0); diff --git a/tests/site_scons/platforms/avr/avr_io.c b/tests/site_scons/platforms/avr/avr_io.c index 30f40c1..e83e6c0 100644 --- a/tests/site_scons/platforms/avr/avr_io.c +++ b/tests/site_scons/platforms/avr/avr_io.c @@ -11,6 +11,10 @@ #undef main extern int app_main(int argc, const char **argv); +// Declare weak symbols in case the main program is compiled as C++ +__attribute__((weak)) int _Z12app_mainiPPc(int argc, const char **argv) {return 0;}; +int app_main(int argc, const char **argv) __attribute__((weak, alias("_Z12app_mainiPPc"))); + struct { uint8_t argc; char args[3][16]; diff --git a/tests/stackusage/SConscript b/tests/stackusage/SConscript index a0c6669..0f092f5 100644 --- a/tests/stackusage/SConscript +++ b/tests/stackusage/SConscript @@ -1,7 +1,10 @@ # Test stack usage +# This test case intentionally performs access outside the legal stack area, +# so it may have to be skipped to avoid false positives on memory safety tools. Import("env") -env.NanopbProto(["stackusage", "stackusage.options"]) -test = env.Program(["stackusage.c", "stackusage.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) -env.RunTest(test) +if not env.get("NOUNSAFE"): + env.NanopbProto(["stackusage", "stackusage.options"]) + test = env.Program(["stackusage.c", "stackusage.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) + env.RunTest(test)