Download chips/yosys/tests/unit/cmds/shuffleTest.cc from STAR-future/Trinity-SciData: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/main/chips/yosys/tests/unit/cmds/shuffleTest.cc
- Command line
-
hf download hf://datasets/STAR-future/Trinity-SciData/chips/yosys/tests/unit/cmds/shuffleTest.cc
-
curl -L -o shuffleTest.cc https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/main/chips/yosys/tests/unit/cmds/shuffleTest.cc
2.29 kB
| YOSYS_NAMESPACE_BEGIN | |
| namespace { | |
| RTLIL::Module *build_module(RTLIL::Design *design) | |
| { | |
| RTLIL::Module *module = design->addModule("\\top"); | |
| for (int i = 0; i < 8; i++) { | |
| RTLIL::Wire *a = module->addWire(stringf("\\a%d", i)); | |
| RTLIL::Wire *y = module->addWire(stringf("\\y%d", i)); | |
| module->addNot(stringf("\\not%d", i), a, y); | |
| module->connect(module->addWire(stringf("\\z%d", i)), y); | |
| module->addMemory(stringf("\\mem%d", i)); | |
| module->addProcess(stringf("\\proc%d", i)); | |
| } | |
| return module; | |
| } | |
| std::vector<std::vector<std::string>> snapshot(const RTLIL::Module *module) | |
| { | |
| std::vector<std::vector<std::string>> result(5); | |
| for (const auto &it : module->wires_) result[0].push_back(std::string(module->twines().str(it.first))); | |
| for (const auto &it : module->cells_) result[1].push_back(std::string(module->twines().str(it.first))); | |
| for (const auto &it : module->memories) result[2].push_back(std::string(module->twines().str(it.first))); | |
| for (const auto &it : module->processes) result[3].push_back(std::string(module->twines().str(it.first))); | |
| for (const auto &it : module->connections_) result[4].push_back(log_signal(it.first) + "=" + log_signal(it.second)); | |
| return result; | |
| } | |
| TEST(ShuffleTest, ReordersAndPreservesContents) | |
| { | |
| RTLIL::Design design; | |
| RTLIL::Module *module = build_module(&design); | |
| auto before = snapshot(module); | |
| Pass::call(&design, "shuffle -seed 3"); | |
| auto after = snapshot(module); | |
| for (size_t i = 0; i < before.size(); i++) { | |
| EXPECT_NE(before[i], after[i]); | |
| std::sort(before[i].begin(), before[i].end()); | |
| std::sort(after[i].begin(), after[i].end()); | |
| EXPECT_EQ(before[i], after[i]); | |
| } | |
| for (const auto &it : module->wires_) | |
| EXPECT_EQ(module->wire(it.first), it.second); | |
| for (const auto &it : module->cells_) | |
| EXPECT_EQ(module->cell(it.first), it.second); | |
| } | |
| TEST(ShuffleTest, SeedIsDeterministic) | |
| { | |
| RTLIL::Design design_a, design_b; | |
| RTLIL::Module *a = build_module(&design_a); | |
| RTLIL::Module *b = build_module(&design_b); | |
| Pass::call(&design_a, "shuffle -seed 7"); | |
| Pass::call(&design_b, "shuffle -seed 7"); | |
| EXPECT_EQ(snapshot(a), snapshot(b)); | |
| Pass::call(&design_b, "shuffle -seed 8"); | |
| EXPECT_NE(snapshot(a), snapshot(b)); | |
| } | |
| } | |
| YOSYS_NAMESPACE_END | |