]> granicus.if.org Git - esp-idf/commitdiff
test/cxx: Test for exception from libstdc++ with -fno-exceptions
authorAnton Maklakov <anton@espressif.com>
Fri, 7 Sep 2018 12:44:25 +0000 (20:44 +0800)
committerAnton Maklakov <anton@espressif.com>
Thu, 20 Sep 2018 10:53:15 +0000 (18:53 +0800)
components/cxx/test/test_cxx.cpp

index 91bac6313ea1f68512ff7331b5def3fa2052c1b7..ead4774d157f551e8ffc9de00d18b7d188a1340a 100644 (file)
@@ -1,5 +1,7 @@
 #include <vector>
-#include <algorithm>
+#include <numeric>
+#include <stdexcept>
+#include <string>
 #include "unity.h"
 #include "esp_log.h"
 #include "freertos/FreeRTOS.h"
@@ -271,6 +273,22 @@ TEST_CASE("c++ exceptions emergency pool", "[cxx] [ignore]")
 #endif
 }
 
+#else // !CONFIG_CXX_EXCEPTIONS
+
+TEST_CASE("std::out_of_range exception when -fno-exceptions", "[cxx][reset=abort,SW_CPU_RESET]")
+{
+    std::vector<int> v(10);
+    v.at(20) = 42;
+    TEST_FAIL_MESSAGE("Unreachable because we are aborted on the line above");
+}
+
+TEST_CASE("std::bad_alloc exception when -fno-exceptions", "[cxx][reset=abort,SW_CPU_RESET]")
+{
+    std::string s = std::string(2000000000, 'a');
+    (void)s;
+    TEST_FAIL_MESSAGE("Unreachable because we are aborted on the line above");
+}
+
 #endif
 
 /* These test cases pull a lot of code from libstdc++ and are disabled for now