From ae02c68df6f26ff24b008ca047ae7750eeecedac Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 Jan 2016 12:27:54 +0200 Subject: Add support for parsing cpu-vendor-os target triplets --- tests/triplet/buildfile | 7 +++ tests/triplet/driver.cxx | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 tests/triplet/buildfile create mode 100644 tests/triplet/driver.cxx (limited to 'tests/triplet') diff --git a/tests/triplet/buildfile b/tests/triplet/buildfile new file mode 100644 index 0000000..237209e --- /dev/null +++ b/tests/triplet/buildfile @@ -0,0 +1,7 @@ +# file : tests/triplet/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} + +include ../../butl/ diff --git a/tests/triplet/driver.cxx b/tests/triplet/driver.cxx new file mode 100644 index 0000000..9d51fed --- /dev/null +++ b/tests/triplet/driver.cxx @@ -0,0 +1,154 @@ +// file : tests/triplet/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include +#include +#include // invalid_argument + +#include + +using namespace std; +using namespace butl; + +static bool +fail (const char*); + +static bool +test (const char*, + const char* canon, + const char* cpu, + const char* vendor, + const char* system, + const char* version); + +int +main () +{ + assert (fail ("")); + assert (fail ("mingw32")); + assert (fail ("-")); + assert (fail ("arm-")); + assert (fail ("-mingw32")); + assert (fail ("a-b-c-d-e")); + assert (fail ("arm-pc--")); + assert (fail ("arm-pc-linux-")); + assert (fail ("arm-pc--gnu")); + + assert (test ("i686-elf", + "i686-elf", + "i686", "", "elf", "")); + + assert (test ("arm-eabi", + "arm-eabi", + "arm", "", "eabi", "")); + + assert (test ("arm-none-eabi", + "arm-eabi", + "arm", "", "eabi", "")); + + assert (test ("arm-none-linux-gnueabi", + "arm-linux-gnueabi", + "arm", "", "linux-gnueabi", "")); + + assert (test ("arm-softfloat-linux-gnu", + "arm-softfloat-linux-gnu", + "arm", "softfloat", "linux-gnu", "")); + + assert (test ("i686-pc-mingw32", + "i686-mingw32", + "i686", "", "mingw32", "")); + + assert (test ("i686-w64-mingw32", + "i686-w64-mingw32", + "i686", "w64", "mingw32", "")); + + assert (test ("i686-lfs-linux-gnu", + "i686-lfs-linux-gnu", + "i686", "lfs", "linux-gnu", "")); + + assert (test ("x86_64-unknown-linux-gnu", + "x86_64-linux-gnu", + "x86_64", "", "linux-gnu", "")); + + assert (test ("x86_64-linux-gnux32", + "x86_64-linux-gnux32", + "x86_64", "", "linux-gnux32", "")); + + // Removal of none-. + // + assert (test ("arm-none", + "arm-none", + "arm", "", "none", "")); + + assert (test ("arm-unknown-none-eabi", + "arm-eabi", + "arm", "", "eabi", "")); + + // Version extraction. + // + assert (test ("x86_64-apple-darwin14.5.0", + "x86_64-apple-darwin14.5.0", + "x86_64", "apple", "darwin", "14.5.0")); + + assert (test ("x86_64-unknown-freebsd10.2", + "x86_64-freebsd10.2", + "x86_64", "", "freebsd", "10.2")); + + assert (test ("x86_64-pc-openbsd5.6", + "x86_64-openbsd5.6", + "x86_64", "", "openbsd", "5.6")); + + assert (test ("sparc-sun-solaris2.9", + "sparc-sun-solaris2.9", + "sparc", "sun", "solaris", "2.9")); +} + +static bool +test (const char* s, + const char* canon, + const char* cpu, + const char* vendor, + const char* system, + const char* version) +{ + string c; + triplet t (s, c); + + auto cmp = [] (const string& a, const char* e, const char* n) -> bool + { + if (a != e) + { + cerr << n << " actual: " << a << endl + << n << " expect: " << e << endl; + + return false; + } + + return true; + }; + + return + cmp (c, canon, "canonical") && + cmp (t.cpu, cpu, "cpu") && + cmp (t.vendor, vendor, "vendor") && + cmp (t.system, system, "system") && + cmp (t.version, version, "version"); +} + +static bool +fail (const char* s) +{ + try + { + triplet t (s); + cerr << "nofail: " << s << endl; + return false; + } + catch (invalid_argument& e) + { + //cerr << e.what () << endl; + } + + return true; +} -- cgit v1.1