forked from platformio/platformio-core
Provide more information when the native program crashed on a host (errored with a negative return code) // Resolve #3429
This commit is contained in:
@ -40,6 +40,10 @@ Please check `Migration guide from 5.x to 6.0 <https://docs.platformio.org/en/la
|
||||
- Dropped support for the "pythonPackages" field in "platform.json" manifest in favor of `Extra Python Dependencies <https://docs.platformio.org/en/latest/scripting/examples/extra_python_packages.html>`__
|
||||
- Fixed an issue when manually removed dependencies from the `"platformio.ini" <https://docs.platformio.org/en/latest/projectconf.html>`__ configuration file were not uninstalled from the storage (`issue #3076 <https://github.com/platformio/platformio-core/issues/3076>`_)
|
||||
|
||||
* **Unit Testing**
|
||||
|
||||
- Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 <https://github.com/platformio/platformio-core/issues/3429>`_)
|
||||
|
||||
* **Static Code Analysis**
|
||||
|
||||
- Added support for the custom `Clang-Tidy <https://docs.platformio.org/en/latest/plus/check-tools/clang-tidy.html>`__ configuration file (`issue #4186 <https://github.com/platformio/platformio-core/issues/4186>`_)
|
||||
|
@ -13,8 +13,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import signal
|
||||
|
||||
from platformio import proc
|
||||
from platformio.unittest.exception import UnitTestError
|
||||
|
||||
|
||||
class TestRunnerNativeMixin:
|
||||
@ -25,5 +27,16 @@ class TestRunnerNativeMixin:
|
||||
stdout=proc.LineBufferedAsyncPipe(self.on_run_output),
|
||||
stderr=proc.LineBufferedAsyncPipe(self.on_run_output),
|
||||
)
|
||||
assert "returncode" in result
|
||||
return result["returncode"] == 0
|
||||
if result["returncode"] == 0:
|
||||
return True
|
||||
try:
|
||||
sig = signal.Signals(abs(result["returncode"]))
|
||||
try:
|
||||
signal_description = signal.strsignal(sig)
|
||||
except AttributeError:
|
||||
signal_description = ""
|
||||
raise UnitTestError(
|
||||
f"Program received signal {sig.name} ({signal_description})"
|
||||
)
|
||||
except ValueError:
|
||||
raise UnitTestError("Program errored with %d code" % result["returncode"])
|
||||
|
@ -71,27 +71,54 @@ int main() {
|
||||
unittest_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
)
|
||||
|
||||
test_dir.join("unittest_transport.h").write(
|
||||
"""
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void unittest_uart_begin(){}
|
||||
void unittest_uart_putchar(char c){}
|
||||
void unittest_uart_flush(){}
|
||||
void unittest_uart_end(){}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
"""
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert all(f in result.output for f in ("setUp called", "tearDown called"))
|
||||
|
||||
|
||||
def test_crashed_program(clirunner, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(){
|
||||
printf("setUp called");
|
||||
}
|
||||
void tearDown(){
|
||||
printf("tearDown called");
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, 1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("Address boundary error is %s", argv[-1]);
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = clirunner.invoke(
|
||||
unittest_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
)
|
||||
assert result.exit_code != 0
|
||||
assert any(
|
||||
s in result.output for s in ("Program received signal", "Program errored with")
|
||||
)
|
||||
|
||||
|
||||
def test_legacy_unity_custom_transport(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
|
Reference in New Issue
Block a user