简体   繁体   English

C++ 多 CPU 架构的单元测试

[英]C++ unit testing for multiple cpu architectures

we develop an app in C++ for ARM and x86 architectures.我们为 ARM 和 x86 架构在 C++ 中开发应用程序。 Of course we integration test our app for both architectures but for now we unit test our app only on x86.当然,我们对这两种架构的应用程序进行了集成测试,但现在我们仅在 x86 上对我们的应用程序进行单元测试。 Is this a possible error source and is it normal to run unit tests for all supported architectures?这是一个可能的错误源吗?为所有支持的架构运行单元测试是否正常?

In theory, as long as your code only uses C++ and you have no undefined behavior, the code should behave the same on all compliant platforms.理论上,只要您的代码仅使用 C++ 并且您没有未定义的行为,那么代码在所有兼容平台上的行为都应该相同。 That's what the standard is supposed to do.这就是标准应该做的事情。

In practice little code is completely contained (you might use libraries or drivers that can behave differently on different platforms) or is absolutely free of undefined behavior (ie int overflow is undefined behavior and it can change with the platform, pointer size can change with the platform, I think there's a flag to issue warnings or errors for all undefined behavior).实际上,很少有代码是完全包含的(您可能会使用在不同平台上表现不同的库或驱动程序)或完全没有未定义的行为(即 int 溢出是未定义的行为,它可以随平台而变化,指针大小可以随平台,我认为有一个标志可以为所有未定义的行为发出警告或错误)。 Even then because of such differences you might get slightly different data-structures layout and you might find some memory or performance issues.即使那样,由于这些差异,您可能会得到稍微不同的数据结构布局,并且您可能会发现一些 memory 或性能问题。

It depends on your code and how much you care about all the platforms.这取决于您的代码以及您对所有平台的关心程度。 If it's mission critical that it works flawless on both platforms then you should run the tests on both.如果它在两个平台上都能完美运行是关键任务,那么您应该在两个平台上运行测试。 If you are mostly dependency and undefined behavior free then maybe a single platform might be enough.如果您主要是依赖和未定义的行为,那么单个平台可能就足够了。

You can also try a setup where you unit test on what you have but every now and then (say daily or weekly) you run the test on the other platform to make sure everything is still fine.你也可以尝试一个设置,对你拥有的东西进行单元测试,但时不时地(比如每天或每周)你在另一个平台上运行测试以确保一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM