Testing C++ code for endian-independence

Viewed 3058

How can I test or check C++ code for endian-independence? It's already implemented, I would just like to verify that it works on both little- and big-endian platforms.

I could write unit tests and run them on the target platforms, but I don't have the hardware. Perhaps emulators?

Are there compile time checks that can be done?

7 Answers

I personally use Travis to test my software hosted on github and it supports running on multiple architectures [1], including s390x which is big endian.

I just had to add this to my .travis.yml:

arch:
  - amd64
  - s390x  # Big endian arch

It's probably not the only CI proposing this, but that's the one I was already using. I run both unit tests and integrated test on both systems which gives me some reasonable confidence that it works fine no matter the endianness.

It's no silver bullet though, I'd like to have an easy way to test it manually too just to ensure there's no hidden error (e.g I'm using SDL, colors could be wrong. I'm using screenshot to validate the output but the code for taking screenshot could have errors compensating the display problem, so the tests could pass with the display being wrong).

[1] https://blog.travis-ci.com/2019-11-12-multi-cpu-architecture-ibm-power-ibm-z

Related