Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

test(cpp): differential fuzz CLI and floor 206

Adeshina Lasisi4e8eb04717a8
diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml
index f0184d94..c9daf87d 100644
--- a/.github/workflows/cpp.yml
+++ b/.github/workflows/cpp.yml
@@ -37,7 +37,7 @@ concurrency:
env:
# The test floor: the number of ctest tests laya-cpp registers (the GoogleTest cases plus
# compile_flags). Raise it with every test added.
- MIN_TESTS: "96"
+ MIN_TESTS: "206"
GOLDENS: ${{ github.workspace }}/.cpp-goldens
LAYA_GOLDENS: ${{ github.workspace }}/.cpp-goldens
LAYA_REQUIRE_GOLDENS: "1" # a missing golden is a failure, never a skip
diff --git a/laya-cpp/CMakeLists.txt b/laya-cpp/CMakeLists.txt
index 9df26e1e..94d1f233 100644
--- a/laya-cpp/CMakeLists.txt
+++ b/laya-cpp/CMakeLists.txt
@@ -48,6 +48,10 @@ if(LAYA_BUILD_TESTS)
target_link_libraries(laya_tests PRIVATE laya GTest::gtest_main)
laya_target_flags(laya_tests)
+ add_executable(laya_cli tests/tools/laya_cli.cpp)
+ target_link_libraries(laya_cli PRIVATE laya)
+ laya_target_flags(laya_cli)
+
include(GoogleTest)
# PRE_TEST: the parametrized rows are counted from the goldens, which exist at test time.
gtest_discover_tests(laya_tests DISCOVERY_MODE PRE_TEST)
diff --git a/laya-cpp/tests/tools/laya_cli.cpp b/laya-cpp/tests/tools/laya_cli.cpp
new file mode 100644
index 00000000..8b5160c9
--- /dev/null
+++ b/laya-cpp/tests/tools/laya_cli.cpp
@@ -0,0 +1,55 @@
+// A tiny line protocol over the library for the differential fuzz (laya-e2e/cpp-lane/fuzz-c1):
+// each stdin line is "<kind> <hex bytes>", each stdout line the hex of the answer.
+// json -> "ok <hex of json.dumps(json.loads(x))>" or "err"
+// lower -> hex of str.lower() sha -> hex digest
+// lang -> "<script>|<language>|<english>|<diacritic>|<non_latin>|<hex mixed_segment>"
+#include <iostream>
+#include <sstream>
+
+#include "laya/lang.hpp"
+#include "laya/pyjson.hpp"
+#include "laya/pyvalue.hpp"
+#include "laya/sha256.hpp"
+#include "laya/unicodedata.hpp"
+
+namespace {
+std::string FromHex(const std::string& h) {
+ std::string out;
+ for (size_t i = 0; i + 1 < h.size(); i += 2) out.push_back(char(std::stoi(h.substr(i, 2), nullptr, 16)));
+ return out;
+}
+std::string Hex(const std::string& s) {
+ static const char* d = "0123456789abcdef";
+ std::string o;
+ for (unsigned char c : s) {
+ o.push_back(d[c >> 4]);
+ o.push_back(d[c & 15]);
+ }
+ return o;
+}
+} // namespace
+
+int main() {
+ std::ios::sync_with_stdio(false);
+ std::string line;
+ while (std::getline(std::cin, line)) {
+ size_t sp = line.find(' ');
+ std::string kind = line.substr(0, sp), data = FromHex(sp == std::string::npos ? "" : line.substr(sp + 1));
+ if (kind == "json") {
+ auto v = laya::pyvalue::Parse(data);
+ auto d = v.ok() ? laya::pyvalue::Dumps(v.value()) : laya::Result<std::string>::Fail("");
+ std::cout << (d.ok() ? "ok " + Hex(d.value()) : std::string("err")) << "\n";
+ } else if (kind == "lower") {
+ std::cout << Hex(laya::unicodedata::Lower(data)) << "\n";
+ } else if (kind == "sha") {
+ std::cout << laya::Sha256Hex(data) << "\n";
+ } else if (kind == "lang") {
+ laya::lang::Analysis a = laya::lang::Analyze(std::string_view(data));
+ std::cout << a.script << "|" << a.language << "|" << (a.english ? 1 : 0) << "|" << laya::pyjson::ReprFloat(a.diacritic_rate)
+ << "|" << laya::pyjson::ReprFloat(a.non_latin_fraction) << "|" << Hex(a.mixed_segment) << "\n";
+ } else {
+ std::cout << "?\n";
+ }
+ }
+ return 0;
+}