working on moving the 'TestCompression' code into its own crate

This commit is contained in:
tmerritt committed 2025-06-01 14:12:48 -04:00
1 parent 21f6e492f6
commit c022b15465
16 files changed
+254 -147

No files matched your search

-4
View File
@@ -3,7 +3,3 @@ coverage = "tarpaulin --out Html --skip-clean --output-dir coverage"
[build] [build]
rustc-wrapper = "sccache" rustc-wrapper = "sccache"
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
+71 -26
View File
@@ -8,31 +8,19 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="8fa1ca42-220d-4157-8efb-e642e4673d11" name="Changes" comment=""> <list default="true" id="8fa1ca42-220d-4157-8efb-e642e4673d11" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/gemma/tests/computer_manager.rs" afterDir="false" /> <change afterPath="$PROJECT_DIR$/gemma/src/test_compression.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/delay_timer.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.cargo/config.toml" beforeDir="false" afterPath="$PROJECT_DIR$/.cargo/config.toml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/instructions.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/keypad.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/registers.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/sound_timer.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/stack.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/gemma/tests/system_memory.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/computer.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/computer.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/instructions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/instructions.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/keypad.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/keypad.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/coverage/tarpaulin-report.html" beforeDir="false" afterPath="$PROJECT_DIR$/coverage/tarpaulin-report.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/util.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/util.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gemma/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/bin/testcompression.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/bin/testcompression.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/src/lib.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/lib.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/state_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/state_tests.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gemma/tests/keypad.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/keypad.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/test_compression_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_compression_tests.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/test_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_utils.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gemma/tests/test_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_utils.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/unit_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/unit_tests.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemma/tests/util_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/util.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemmatelnet/src/telnet_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmatelnet/src/telnet_utils.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemmautil/src/bin/bin2hex.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmautil/src/bin/bin2hex.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gemmautil/src/bin/ch8asm.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmautil/src/bin/ch8asm.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_001_round_trip_serialize_deserialize.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_002_round_trip_serialize_deserialize_compressed.tflt" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_002_round_trip_serialize_deserialize_compressed.tflt.uncompressed" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/resources/test/state/video_lowres_schip_draw_chip8_sprite_result.json" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -52,9 +40,9 @@
<component name="MacroExpansionManager"> <component name="MacroExpansionManager">
<option name="directoryName" value="q85ybjmm" /> <option name="directoryName" value="q85ybjmm" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{ <component name="ProjectColorInfo">{
"associatedIndex": 5 &quot;associatedIndex&quot;: 5
}]]></component> }</component>
<component name="ProjectId" id="2xpB7kQEFEwMZf3OlpLuqA97yi7" /> <component name="ProjectId" id="2xpB7kQEFEwMZf3OlpLuqA97yi7" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
@@ -62,7 +50,10 @@
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"Cargo.Build `Test compress_file_to_array`.executor": "Run",
"Cargo.Test compress_file_to_array.executor": "Debug",
"Cargo.Test keypad.executor": "Debug", "Cargo.Test keypad.executor": "Debug",
"Cargo.Test state_to_json.executor": "Debug",
"Cargo.Test video_lowres_schip_draw_chip8_sprite.executor": "Debug", "Cargo.Test video_lowres_schip_draw_chip8_sprite.executor": "Debug",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.rust.reset.selective.auto.import": "true", "RunOnceActivity.rust.reset.selective.auto.import": "true",
@@ -72,10 +63,16 @@
"node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.eslint": "(autodetect)",
"nodejs_package_manager_path": "npm", "nodejs_package_manager_path": "npm",
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true", "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
"org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
"org.rust.first.attach.projects": "true" "org.rust.first.attach.projects": "true"
},
"keyToStringList": {
"com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
"Rust"
]
} }
}]]></component> }]]></component>
<component name="RunManager" selected="Cargo.Test keypad"> <component name="RunManager" selected="Cargo.Test compress_file_to_array">
<configuration name="Run bin2hex" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> <configuration name="Run bin2hex" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package gemmautil --bin bin2hex" /> <option name="command" value="run --package gemmautil --bin bin2hex" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
@@ -178,6 +175,23 @@
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" /> <option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="Test compress_file_to_array" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package gemma --test test_compression_tests compress_file_to_array -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test keypad" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true"> <configuration name="Test keypad" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package gemma --test keypad" /> <option name="command" value="test --package gemma --test keypad" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
@@ -195,6 +209,23 @@
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" /> <option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="Test state_to_json" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="command" value="test --package gemma --test computer_tests state_to_json -- --exact" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test trevors_chip8_toy" type="CargoCommandRunConfiguration" factoryName="Cargo Command"> <configuration name="Test trevors_chip8_toy" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="test --workspace" /> <option name="command" value="test --workspace" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" /> <option name="workingDirectory" value="file://$PROJECT_DIR$" />
@@ -231,6 +262,8 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Cargo.Test compress_file_to_array" />
<item itemvalue="Cargo.Test state_to_json" />
<item itemvalue="Cargo.Test keypad" /> <item itemvalue="Cargo.Test keypad" />
<item itemvalue="Cargo.Test video_lowres_schip_draw_chip8_sprite" /> <item itemvalue="Cargo.Test video_lowres_schip_draw_chip8_sprite" />
</list> </list>
@@ -248,10 +281,22 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1748624969802</updated> <updated>1748624969802</updated>
<workItem from="1748624970827" duration="3451000" /> <workItem from="1748624970827" duration="3451000" />
<workItem from="1748791611817" duration="1715000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/gemma/tests/computer_tests.rs</url>
<line>149</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>
Generated
+11
View File
@@ -1996,6 +1996,7 @@ dependencies = [
"dimensioned", "dimensioned",
"flate2", "flate2",
"hex", "hex",
"lipsum",
"log", "log",
"pretty_env_logger", "pretty_env_logger",
"rand 0.9.1", "rand 0.9.1",
@@ -2906,6 +2907,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "lipsum"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "636860251af8963cc40f6b4baadee105f02e21b28131d76eba8e40ce84ab8064"
dependencies = [
"rand 0.8.5",
"rand_chacha 0.3.1",
]
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.8.0" version = "0.8.0"
+1
View File
@@ -32,3 +32,4 @@ eframe = { version = "0.29" }
# Testing # Testing
tempfile = "3.20" tempfile = "3.20"
lipsum = "0.9"
+2 -2
View File
@@ -118,8 +118,8 @@
<body> <body>
<div id="root"></div> <div id="root"></div>
<script> <script>
var data = {"files":[{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","speedtest.rs"],"content":"use gemma::chip8::computer_manager::Chip8ComputerManager;\nuse std::fs::File;\nuse std::io::Read;\nuse std::ops::Add;\nuse std::path::Path;\nuse std::time::{Duration, Instant};\n\nconst ROM_ROOT: \u0026str = \"resources/roms\";\n\nfn main() {\n let mut x = Chip8ComputerManager::new();\n\n let mut buffer = Vec::new();\n let mut input_file =\n File::open(Path::new(\u0026(ROM_ROOT.to_string() + \"/mandelbrot_bench.ch8\"))).expect(\"derp\");\n input_file\n .read_to_end(\u0026mut buffer)\n .expect(\"unable to read file\");\n x.load_new_program_to_system_memory((\u0026*buffer).into());\n\n for _ in 0..10 {\n let start_time = Instant::now();\n let mut num_cycles = 0;\n // how many instructions in 10s.\n let end_time = start_time.add(Duration::from_secs(10));\n while Instant::now().le(\u0026end_time) {\n num_cycles += 1;\n x.step();\n }\n\n let num = num_cycles\n .to_string()\n .as_bytes()\n .rchunks(3)\n .rev()\n .map(std::str::from_utf8)\n .collect::\u003cResult\u003cVec\u003c\u0026str\u003e, _\u003e\u003e()\n .unwrap()\n .join(\",\"); // separator\n\n let num_ips = num_cycles / 1000000;\n println!(\"Completed at {num_ips} Mips. ({num})\");\n }\n}\n","traces":[{"line":10,"address":[458832,460780,460845],"length":1,"stats":{"Line":0}},{"line":11,"address":[458839],"length":1,"stats":{"Line":0}},{"line":13,"address":[458856],"length":1,"stats":{"Line":0}},{"line":14,"address":[458919,458991],"length":1,"stats":{"Line":0}},{"line":16,"address":[459251],"length":1,"stats":{"Line":0}},{"line":19,"address":[459336],"length":1,"stats":{"Line":0}},{"line":21,"address":[459436],"length":1,"stats":{"Line":0}},{"line":22,"address":[459589,459671],"length":1,"stats":{"Line":0}},{"line":23,"address":[459700],"length":1,"stats":{"Line":0}},{"line":25,"address":[459716],"length":1,"stats":{"Line":0}},{"line":26,"address":[459794],"length":1,"stats":{"Line":0}},{"line":27,"address":[460819,459898,460793],"length":1,"stats":{"Line":0}},{"line":28,"address":[460800,460840],"length":1,"stats":{"Line":0}},{"line":31,"address":[459891,460323,459933,460024,460390],"length":1,"stats":{"Line":0}},{"line":41,"address":[460537,460626],"length":1,"stats":{"Line":0}},{"line":42,"address":[460599,460646],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":16},{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","testcompression.rs"],"content":"use std::fs;\nuse std::fs::File;\nuse clap::{Parser, Subcommand};\nuse flate2::{write::{GzEncoder, GzDecoder}, Compression};\nuse std::io::{Cursor, Read, Write};\nuse std::path::PathBuf;\nuse std::io::prelude::*;\n\n#[derive(Parser)]\n#[command(author, version, about = \"Compress or decompress a string\", long_about = None)]\nstruct Cli {\n /// Subcommand: either 'compress' or 'decompress'\n #[command(subcommand)]\n command: Commands,\n}\n\n#[derive(Subcommand)]\nenum Commands {\n /// Compress the input string\n Compress {\n /// The string to compress\n input: String,\n },\n /// Decompress the input string (must be compressed format)\n Decompress {\n /// The compressed string to decompress, in hex format\n input: String,\n },\n CompressFile {\n input: PathBuf\n },\n DecompressFile {\n input: PathBuf\n }\n}\n\nfn compress_string(input: \u0026str) -\u003e Vec\u003cu8\u003e {\n let mut encoder = GzEncoder::new(Vec::new(), Compression::default());\n encoder.write_all(input.as_bytes()).expect(\"Compression failed\");\n encoder.finish().expect(\"Failed to finish compression\")\n}\n\nfn decompress_string(input: \u0026[u8]) -\u003e String {\n let mut decoder = GzDecoder::new(Vec::new());\n decoder.write_all(input).expect(\"Decompression failed\");\n let decompressed_data = decoder.finish().expect(\"Failed to finish decompression\");\n String::from_utf8(decompressed_data).expect(\"Invalid UTF-8\")\n}\n\nfn compress_file(input_path: \u0026PathBuf) {\n let target_file_name = format!(\"{}.tflt\", input_path.display());\n println!(\"TARGET_FILE_NAME: {}\", target_file_name);\n let input_data = fs::read(input_path).expect(\"Failed to read input file\");\n let mut encoder = GzEncoder::new(Vec::new(), Compression::default());\n encoder.write_all(\u0026input_data).expect(\"Compression failed\");\n let compressed_data = encoder.finish().expect(\"Failed to finish compression\");\n let target_file = File::create(target_file_name);\n target_file.unwrap().write_all(\u0026compressed_data).unwrap()\n}\n\nfn decompress_file(input_path: \u0026PathBuf) {\n let target_file_name = format!(\"{}.uncompressed\", input_path.dispLine truncated var data = {"files":[{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","speedtest.rs"],"content":"use gemma::chip8::computer_manager::Chip8ComputerManager;\nuse std::fs::File;\nuse std::io::Read;\nuse std::ops::Add;\nuse std::path::Path;\nuse std::time::{Duration, Instant};\n\nconst ROM_ROOT: \u0026str = \"resources/roms\";\n\nfn main() {\n let mut x = Chip8ComputerManager::new();\n\n let mut buffer = Vec::new();\n let mut input_file =\n File::open(Path::new(\u0026(ROM_ROOT.to_string() + \"/mandelbrot_bench.ch8\"))).expect(\"derp\");\n input_file\n .read_to_end(\u0026mut buffer)\n .expect(\"unable to read file\");\n x.load_new_program_to_system_memory((\u0026*buffer).into());\n\n for _ in 0..10 {\n let start_time = Instant::now();\n let mut num_cycles = 0;\n // how many instructions in 10s.\n let end_time = start_time.add(Duration::from_secs(10));\n while Instant::now().le(\u0026end_time) {\n num_cycles += 1;\n x.step();\n }\n\n let num = num_cycles\n .to_string()\n .as_bytes()\n .rchunks(3)\n .rev()\n .map(std::str::from_utf8)\n .collect::\u003cResult\u003cVec\u003c\u0026str\u003e, _\u003e\u003e()\n .unwrap()\n .join(\",\"); // separator\n\n let num_ips = num_cycles / 1000000;\n println!(\"Completed at {num_ips} Mips. ({num})\");\n }\n}\n","traces":[{"line":10,"address":[880112,881936,881871],"length":1,"stats":{"Line":0}},{"line":11,"address":[880119],"length":1,"stats":{"Line":0}},{"line":13,"address":[880136],"length":1,"stats":{"Line":0}},{"line":14,"address":[880271,880199],"length":1,"stats":{"Line":0}},{"line":16,"address":[880531],"length":1,"stats":{"Line":0}},{"line":19,"address":[880616],"length":1,"stats":{"Line":0}},{"line":21,"address":[880716],"length":1,"stats":{"Line":0}},{"line":22,"address":[880869,880939],"length":1,"stats":{"Line":0}},{"line":23,"address":[880968],"length":1,"stats":{"Line":0}},{"line":25,"address":[880984],"length":1,"stats":{"Line":0}},{"line":26,"address":[881062],"length":1,"stats":{"Line":0}},{"line":27,"address":[881166,881910,881884],"length":1,"stats":{"Line":0}},{"line":28,"address":[881891,881931],"length":1,"stats":{"Line":0}},{"line":31,"address":[881477,881272,881159,881201],"length":1,"stats":{"Line":0}},{"line":41,"address":[881628,881717],"length":1,"stats":{"Line":0}},{"line":42,"address":[881690,881737],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":16},{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","testcompression.rs"],"content":"/// TestCompression\n///\n/// Utility for [de]compressing tests for Gemma\n///\n/// Usage: testcompression \u003cCOMMAND\u003e\n//\n// Commands:\n// compress Compress the input string\n// decompress Decompress the input string (must be compressed format)\n// help Print this message or the help of the given subcommand(s)\n//\n// Options:\n// -h, --help Print help\n// -V, --version Print version\n///\n/// Limitations:\n/// - Uncompressed files must only contain printable ASCII characters\n/// - Stuff I don't know about yet\n\n\nuse std::fs;\nuse std::fs::File;\nuse clap::{Parser, Subcommand};\nuse std::path::{Path, PathBuf};\nuse std::io::prelude::*;\nuse std::io::Read;\nuse std::io::Write;\nuse flate2::Compression;\nuse flate2::write::{DeflateEncoder, GzEncoder, ZlibEncoder};\nuse gemma::constants::{TESTS_ROOT, TEST_ROM_ROOT};\nuse flate2::read::{DeflateDecoder};\nuse std::io::prelude::*;\nuse std::io;\nuse std::ptr::write;\nuse log::{debug, info};\n\n#[derive(Parser)]\n#[command(author, version, about = \"Compress or decompress a string\", long_about = None)]\nstruct Cli {\n /// Subcommand: either 'compress' or 'decompress'\n #[command(subcommand)]\n command: Commands,\n}\n\n#[derive(Subcommand)]\nenum Commands {\n /// Compress the input file\n Compress {\n /// The string to compress, in plain text\n input: PathBuf,\n },\n /// Decompress the input file\n Decompress {\n /// The compressed string to decompress, in hex format\n input: PathBuf,\n }\n}\n\nfn compress_file(input_path: \u0026PathBuf) -\u003e io::Result\u003c()\u003e {\n let compressed_bytes= compress_file_to_array(input_path);\n let output_filename = input_path.with_extension(\"deflated\");\n let mut output_file = File::create(\u0026output_filename)?;\n output_file.write_all(\u0026compressed_bytes.unwrap())?;\n Ok(())\n}\n\nfn compress_file_to_array(input_path: \u0026Path) -\u003e Result\u003cVec\u003cu8\u003e, String\u003e {\n let mut file = File::open(input_path)\n .map_err(|e| std::io::Error::new(e.kind(), format!(\"Unable to open input path [{}]: {}\", input_path.display(), e)));\n\n let mut read_buffer = Vec::new();\n let mut write_buffer = Vec::new();\Line truncated
var previousData = {"files":[{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","speedtest.rs"],"content":"use gemma::chip8::computer_manager::Chip8ComputerManager;\nuse std::fs::File;\nuse std::io::Read;\nuse std::ops::Add;\nuse std::path::Path;\nuse std::time::{Duration, Instant};\n\nconst ROM_ROOT: \u0026str = \"resources/roms\";\n\nfn main() {\n let mut x = Chip8ComputerManager::new();\n\n let mut buffer = Vec::new();\n let mut input_file =\n File::open(Path::new(\u0026(ROM_ROOT.to_string() + \"/mandelbrot_bench.ch8\"))).expect(\"derp\");\n input_file\n .read_to_end(\u0026mut buffer)\n .expect(\"unable to read file\");\n x.load_new_program_to_system_memory((\u0026*buffer).into());\n\n for _ in 0..10 {\n let start_time = Instant::now();\n let mut num_cycles = 0;\n // how many instructions in 10s.\n let end_time = start_time.add(Duration::from_secs(10));\n while Instant::now().le(\u0026end_time) {\n num_cycles += 1;\n x.step();\n }\n\n let num = num_cycles\n .to_string()\n .as_bytes()\n .rchunks(3)\n .rev()\n .map(std::str::from_utf8)\n .collect::\u003cResult\u003cVec\u003c\u0026str\u003e, _\u003e\u003e()\n .unwrap()\n .join(\",\"); // separator\n\n let num_ips = num_cycles / 1000000;\n println!(\"Completed at {num_ips} Mips. ({num})\");\n }\n}\n","traces":[{"line":10,"address":[460780,460845,458832],"length":1,"stats":{"Line":0}},{"line":11,"address":[458839],"length":1,"stats":{"Line":0}},{"line":13,"address":[458856],"length":1,"stats":{"Line":0}},{"line":14,"address":[458919,458991],"length":1,"stats":{"Line":0}},{"line":16,"address":[459251],"length":1,"stats":{"Line":0}},{"line":19,"address":[459336],"length":1,"stats":{"Line":0}},{"line":21,"address":[459436],"length":1,"stats":{"Line":0}},{"line":22,"address":[459589,459671],"length":1,"stats":{"Line":0}},{"line":23,"address":[459700],"length":1,"stats":{"Line":0}},{"line":25,"address":[459716],"length":1,"stats":{"Line":0}},{"line":26,"address":[459794],"length":1,"stats":{"Line":0}},{"line":27,"address":[459898,460793,460819],"length":1,"stats":{"Line":0}},{"line":28,"address":[460800,460840],"length":1,"stats":{"Line":0}},{"line":31,"address":[459933,460390,459891,460323,460024],"length":1,"stats":{"Line":0}},{"line":41,"address":[460537,460626],"length":1,"stats":{"Line":0}},{"line":42,"address":[460599,460646],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":16},{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","testcompression.rs"],"content":"use std::fs;\nuse std::fs::File;\nuse clap::{Parser, Subcommand};\nuse flate2::{write::{GzEncoder, GzDecoder}, Compression};\nuse std::io::{Cursor, Read, Write};\nuse std::path::PathBuf;\nuse std::io::prelude::*;\n\n#[derive(Parser)]\n#[command(author, version, about = \"Compress or decompress a string\", long_about = None)]\nstruct Cli {\n /// Subcommand: either 'compress' or 'decompress'\n #[command(subcommand)]\n command: Commands,\n}\n\n#[derive(Subcommand)]\nenum Commands {\n /// Compress the input string\n Compress {\n /// The string to compress\n input: String,\n },\n /// Decompress the input string (must be compressed format)\n Decompress {\n /// The compressed string to decompress, in hex format\n input: String,\n },\n CompressFile {\n input: PathBuf\n },\n DecompressFile {\n input: PathBuf\n }\n}\n\nfn compress_string(input: \u0026str) -\u003e Vec\u003cu8\u003e {\n let mut encoder = GzEncoder::new(Vec::new(), Compression::default());\n encoder.write_all(input.as_bytes()).expect(\"Compression failed\");\n encoder.finish().expect(\"Failed to finish compression\")\n}\n\nfn decompress_string(input: \u0026[u8]) -\u003e String {\n let mut decoder = GzDecoder::new(Vec::new());\n decoder.write_all(input).expect(\"Decompression failed\");\n let decompressed_data = decoder.finish().expect(\"Failed to finish decompression\");\n String::from_utf8(decompressed_data).expect(\"Invalid UTF-8\")\n}\n\nfn compress_file(input_path: \u0026PathBuf) {\n let target_file_name = format!(\"{}.tflt\", input_path.display());\n println!(\"TARGET_FILE_NAME: {}\", target_file_name);\n let input_data = fs::read(input_path).expect(\"Failed to read input file\");\n let mut encoder = GzEncoder::new(Vec::new(), Compression::default());\n encoder.write_all(\u0026input_data).expect(\"Compression failed\");\n let compressed_data = encoder.finish().expect(\"Failed to finish compression\");\n let target_file = File::create(target_file_name);\n target_file.unwrap().write_all(\u0026compressed_data).unwrap()\n}\n\nfn decompress_file(input_path: \u0026PathBuf) {\n let target_file_name = format!(\"{}.uncompressed\", input_pLine truncated var previousData = {"files":[{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","bin","speedtest.rs"],"content":"use gemma::chip8::computer_manager::Chip8ComputerManager;\nuse std::fs::File;\nuse std::io::Read;\nuse std::ops::Add;\nuse std::path::Path;\nuse std::time::{Duration, Instant};\n\nconst ROM_ROOT: \u0026str = \"resources/roms\";\n\nfn main() {\n let mut x = Chip8ComputerManager::new();\n\n let mut buffer = Vec::new();\n let mut input_file =\n File::open(Path::new(\u0026(ROM_ROOT.to_string() + \"/mandelbrot_bench.ch8\"))).expect(\"derp\");\n input_file\n .read_to_end(\u0026mut buffer)\n .expect(\"unable to read file\");\n x.load_new_program_to_system_memory((\u0026*buffer).into());\n\n for _ in 0..10 {\n let start_time = Instant::now();\n let mut num_cycles = 0;\n // how many instructions in 10s.\n let end_time = start_time.add(Duration::from_secs(10));\n while Instant::now().le(\u0026end_time) {\n num_cycles += 1;\n x.step();\n }\n\n let num = num_cycles\n .to_string()\n .as_bytes()\n .rchunks(3)\n .rev()\n .map(std::str::from_utf8)\n .collect::\u003cResult\u003cVec\u003c\u0026str\u003e, _\u003e\u003e()\n .unwrap()\n .join(\",\"); // separator\n\n let num_ips = num_cycles / 1000000;\n println!(\"Completed at {num_ips} Mips. ({num})\");\n }\n}\n","traces":[{"line":11,"address":[254592,256682,256747],"length":1,"stats":{"Line":0}},{"line":12,"address":[254599],"length":1,"stats":{"Line":0}},{"line":14,"address":[254616],"length":1,"stats":{"Line":0}},{"line":15,"address":[254747,254679],"length":1,"stats":{"Line":0}},{"line":17,"address":[254999],"length":1,"stats":{"Line":0}},{"line":20,"address":[255084],"length":1,"stats":{"Line":0}},{"line":22,"address":[255184],"length":1,"stats":{"Line":0}},{"line":23,"address":[255415,255333],"length":1,"stats":{"Line":0}},{"line":24,"address":[255444],"length":1,"stats":{"Line":0}},{"line":26,"address":[255460],"length":1,"stats":{"Line":0}},{"line":27,"address":[255538],"length":1,"stats":{"Line":0}},{"line":28,"address":[256695,255642,256721],"length":1,"stats":{"Line":0}},{"line":29,"address":[256702,256742],"length":1,"stats":{"Line":0}},{"line":32,"address":[255635,256067,256134,255677,255768],"length":1,"stats":{"Line":0}},{"line":42,"address":[256281,256445],"length":1,"stats":{"Line":0}},{"line":43,"address":[256575],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":16},{"path":["/","home","tmerritt","Projects","trevors_chip8_toy","gemma","src","chip8","computer.rs"],"content":"use crate::chip8::delay_timer::DelayTimer;\nuse crate::chip8::keypad::Keypad;\nuse crate::chip8::quirk_modes::QuirkMode;\nuse crate::chip8::registers::Chip8Registers;\nuse crate::chip8::sound_timer::SoundTimer;\nuse crate::chip8::stack::Chip8Stack;\nuse log::debug;\nuse serde::{Deserialize, Serialize};\nuse super::{\n cpu_states::Chip8CpuStates, instructions::Chip8CpuInstructions,\n system_memory::Chip8SystemMemory, video::Chip8Video,\n};\n\n#[derive(Clone, Serialize, Deserialize, Debug)]\npub struct Chip8Computer {\n pub num_cycles: i32,\n pub memory: Chip8SystemMemory,\n pub registers: Chip8Registers,\n pub sound_timer: SoundTimer,\n pub delay_timer: DelayTimer,\n pub video_memory: Chip8Video,\n pub state: Chip8CpuStates,\n pub keypad: Keypad,\n pub stack: Chip8Stack,\n pub quirk_mode: QuirkMode,\n}\n\nimpl PartialEq for Chip8Computer {\n fn eq(\u0026self, other: \u0026Self) -\u003e bool {\n self.video_memory.format_as_string() == other.video_memory.format_as_string() \u0026\u0026\n self.keypad.format_as_string() == other.keypad.format_as_string() \u0026\u0026\n self.num_cycles == other.num_cycles \u0026\u0026\n self.memory == other.memory\n }\n}\n\nimpl Default for Chip8Computer {\n fn default() -\u003e Self {\n Self {\n num_cycles: 0,\n memory: Chip8SystemMemory::default(),\n video_memory: Chip8Video::default(),\n registers: Chip8Registers::default(),\n sound_timer: SoundTimer::new(),\n delay_timer: DelayTimer::new(),\n state: Chip8CpuStates::default(),\n keypad: Keypad::default(),\n stack: Chip8Stack::default(),\n quirk_mode: QuirkMode::default(),\n }\n }\n}\n\nimpl Chip8Computer {\n pub fn reset(\u0026mut self, quirk_mode: QuirkMode) {\n self.video_memory.reset();\n self.num_cycles = 0;\n self.registers.reset();\n self.delay_timer.reset();\n self.sound_timer.reset();\n self.stack.reset();\n self.memory.reset(quirk_mode);\n self.quirk_mode = quirk_mode;\n }\n\n pub fn dump_keypad_to_string(\u0026self) -\u003e String {\n self.keypad.format_as_sLine truncated
</script> </script>
<script crossorigin>/** @license React v16.13.1 <script crossorigin>/** @license React v16.13.1
* react.production.min.js * react.production.min.js
+2
View File
@@ -15,4 +15,6 @@ flate2.workspace = true
clap.workspace = true clap.workspace = true
hex.workspace = true hex.workspace = true
log.workspace = true log.workspace = true
# Testing
tempfile.workspace = true tempfile.workspace = true
lipsum.workspace = true
+3 -49
View File
@@ -17,7 +17,6 @@
/// - Uncompressed files must only contain printable ASCII characters /// - Uncompressed files must only contain printable ASCII characters
/// - Stuff I don't know about yet /// - Stuff I don't know about yet
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@@ -33,6 +32,7 @@ use std::io::prelude::*;
use std::io; use std::io;
use std::ptr::write; use std::ptr::write;
use log::{debug, info}; use log::{debug, info};
use gemma::test_compression::TestCompression;
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about = "Compress or decompress a string", long_about = None)] #[command(author, version, about = "Compress or decompress a string", long_about = None)]
@@ -56,52 +56,6 @@ enum Commands {
} }
} }
fn compress_file(input_path: &PathBuf) -> io::Result<()> {
let compressed_bytes= compress_file_to_array(input_path);
let output_filename = input_path.with_extension("deflated");
let mut output_file = File::create(&output_filename)?;
output_file.write_all(&compressed_bytes.unwrap())?;
Ok(())
}
fn compress_file_to_array(input_path: &Path) -> Result<Vec<u8>, String> {
let mut file = File::open(input_path)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
let mut read_buffer = Vec::new();
let mut write_buffer = Vec::new();
file.unwrap().read_to_end(&mut read_buffer)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to read input file [{}]: {}", input_path.display(), e)));
let mut encoder = DeflateEncoder::new(read_buffer, Compression::default());
encoder.write_all(&write_buffer)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to compress data for [{}]: {}", input_path.display(), e)));
debug!("Compressed file from path: {}", input_path.display());
Ok(write_buffer)
}
fn decompress_file_to_array(input_path: &Path) -> Vec<u8> {
let file = File::open(input_path)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
let mut decoder = DeflateDecoder::new(file.unwrap());
let mut return_vec = Vec::new();
decoder.read_to_end(&mut return_vec)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to decompress data for [{}]: {}", input_path.display(), e)));
debug!("Decompressed file from path: {}", input_path.display());
return_vec
}
fn decompress_file(input_path: &PathBuf) -> io::Result<()> {
let decompressed_bytes = decompress_file_to_array(input_path);
let output_path = input_path.with_extension("inflated");
let mut output_file = File::create(&output_path)?;
output_file.write_all(&decompressed_bytes).expect(format!("Unable to write compressed data to [{}]", output_path.display()).as_str());
Ok(())
}
fn main() { fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
@@ -109,10 +63,10 @@ fn main() {
match cli.command { match cli.command {
Commands::Compress { input } => { Commands::Compress { input } => {
compress_file(&input).expect(format!("Unable to compress {}", input.display()).as_str()); TestCompression::compress_file(&input).expect(format!("Unable to compress {}", input.display()).as_str());
} }
Commands::Decompress { input } => { Commands::Decompress { input } => {
decompress_file(&input).expect(format!("Unable to decompress {}", input.display()).as_str()); TestCompression::decompress_file(&input).expect(format!("Unable to decompress {}", input.display()).as_str());
} }
} }
} }
+2 -1
View File
@@ -15,4 +15,5 @@ pub mod chip8 {
pub mod quirk_modes; pub mod quirk_modes;
} }
pub mod constants; pub mod constants;
pub mod test_compression;
+74
View File
@@ -0,0 +1,74 @@
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use flate2::Compression;
use flate2::read::DeflateDecoder;
use flate2::write::DeflateEncoder;
use log::debug;
pub struct TestCompression {}
impl TestCompression {
pub fn compress_file(input_path: &PathBuf) -> io::Result<()> {
let compressed_bytes= TestCompression::compress_file_to_array(input_path);
let output_filename = input_path.with_extension("deflated");
let mut output_file = File::create(&output_filename)?;
output_file.write_all(&compressed_bytes.unwrap())?;
Ok(())
}
pub fn compress_file_to_array(input_path: &Path) -> Result<Vec<u8>, String> {
let mut file = File::open(input_path)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
let mut read_buffer = Vec::new();
let mut write_buffer = Vec::new();
file.unwrap().read_to_end(&mut read_buffer)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to read input file [{}]: {}", input_path.display(), e)));
let mut encoder = DeflateEncoder::new(read_buffer, Compression::default());
encoder.write_all(&write_buffer)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to compress data for [{}]: {}", input_path.display(), e)));
debug!("Compressed file from path: {}", input_path.display());
Ok(write_buffer)
}
pub fn decompress_file_to_array(input_path: &Path) -> Vec<u8> {
let file = File::open(input_path)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
let mut decoder = DeflateDecoder::new(file.unwrap());
let mut return_vec = Vec::new();
decoder.read_to_end(&mut return_vec)
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to decompress data for [{}]: {}", input_path.display(), e)));
debug!("Decompressed file from path: {}", input_path.display());
return_vec
}
pub fn decompress_file(input_path: &PathBuf) -> io::Result<()> {
let decompressed_bytes = TestCompression::decompress_file_to_array(input_path);
let output_path = input_path.with_extension("inflated");
let mut output_file = File::create(&output_path)?;
output_file.write_all(&decompressed_bytes).expect(format!("Unable to write compressed data to [{}]", output_path.display()).as_str());
Ok(())
}
pub fn compress_string(input: &str) -> Vec<u8> {
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
encoder
.write_all(input.as_bytes())
.expect("Failed to write data");
encoder.finish().expect("Failed to finish compression")
}
pub fn decompress_to_string(compressed_data: &[u8]) -> Result<String, std::io::Error> {
let mut decoder = DeflateDecoder::new(compressed_data);
let mut decompressed = String::new();
decoder.read_to_string(&mut decompressed)?;
Ok(decompressed)
}
}
+14 -2
View File
@@ -92,7 +92,7 @@ fn level3_compressed_test() {
assert_eq!( assert_eq!(
x.dump_video_to_string(), x.dump_video_to_string(),
load_compressed_result("gemma_integration.corax_plus") load_compressed_result("gemma_integration_corax_plus")
); );
} }
@@ -132,7 +132,6 @@ fn level4_test() {
); );
} }
#[test] #[test]
fn partial_eq_chip8computer() { fn partial_eq_chip8computer() {
let x = Chip8Computer::new(); let x = Chip8Computer::new();
@@ -140,6 +139,19 @@ fn partial_eq_chip8computer() {
assert_eq!(x, y) assert_eq!(x, y)
} }
#[test]
fn state_to_json() {
let x = Chip8Computer::new();
let expected = load_compressed_result("gemma_integration_state_to_json1");
let actual = x.dump_state_to_json();
println!("ACTUAL:: [{}]", actual);
assert_eq!(
actual,
expected
);
}
#[test] #[test]
fn tick_when_not_ready() {} fn tick_when_not_ready() {}
+4 -9
View File
@@ -1,6 +1,6 @@
mod test_utils; mod test_utils;
use gemma::chip8::keypad::Keypad;
use crate::test_utils::read_compressed_test_result; use crate::test_utils::read_compressed_test_result;
use gemma::chip8::keypad::Keypad;
#[test] #[test]
fn keypad_keys_check() { fn keypad_keys_check() {
@@ -20,17 +20,12 @@ fn keypad_keys_check() {
} }
#[test] #[test]
#[ignore]
fn keypad_string_format_test() { fn keypad_string_format_test() {
let k = Keypad::new();
let expected_result = read_compressed_test_result("gemma_keypad_string_result"); let expected_result = read_compressed_test_result("gemma_keypad_string_result");
let actual_result = k.format_as_string(); let actual_result = Keypad::new().format_as_string();
println!("EXPECTING [{}]", expected_result); println!("EXPECTING [{}]", expected_result);
println!("GOT [{}]", actual_result); println!("GOT [{}]", actual_result);
assert_eq!( assert_eq!(actual_result, expected_result);
k.format_as_string(),
read_compressed_test_result("gemma_keypad_string_result")
);
} }
+39 -3
View File
@@ -1,4 +1,7 @@
use crate::test_utils::{compress_string, decompress_to_string}; use std::io::Write;
use std::path::Path;
use tempfile::{NamedTempFile, tempfile};
use gemma::test_compression::TestCompression;
mod test_utils; mod test_utils;
@@ -10,9 +13,42 @@ fn smoke() {
#[test] #[test]
fn round_trip() { fn round_trip() {
let text_to_process = "The quick brown fox jumps over the lazy dog."; let text_to_process = "The quick brown fox jumps over the lazy dog.";
let compressed = compress_string(text_to_process); let compressed = TestCompression::compress_string(text_to_process);
let decompressed = decompress_to_string(&compressed).unwrap(); let decompressed = TestCompression::decompress_to_string(&compressed).unwrap();
assert_eq!(text_to_process, decompressed); assert_eq!(text_to_process, decompressed);
} }
#[test]
fn compress_file_to_array() {
// create a file with plain text...
// ...compress it to in-memory data
// ...confirm that matches predefined data
}
#[test]
fn compress_file() {
// create a file with plain text...
// ...compress it to a temp file...
// ...read the compressed data...
// ...verify it matches initial plain text
}
#[test]
fn decompress_file_to_array() {
// crate a file with plain text...
// ...write the compressed version
// ...
}
#[test]
fn decompress_file() {
}
+5 -51
View File
@@ -4,28 +4,16 @@ use flate2::Compression;
use std::fs::File; use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
use tempfile::tempfile; use tempfile::tempfile;
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/"; use gemma::test_compression::TestCompression;
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
const TEST_ROMS_SAMPLE_DIR: &str = "../resources/roms/";
#[test] #[test]
fn smoke() { fn smoke() {
assert!(true) assert!(true)
} }
pub fn compress_string(input: &str) -> Vec<u8> {
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
encoder
.write_all(input.as_bytes())
.expect("Failed to write data");
encoder.finish().expect("Failed to finish compression")
}
pub fn decompress_to_string(compressed_data: &[u8]) -> Result<String, std::io::Error> {
let mut decoder = DeflateDecoder::new(compressed_data);
let mut decompressed = String::new();
decoder.read_to_string(&mut decompressed)?;
Ok(decompressed)
}
/// Read a compressed test result and return the expected result /// Read a compressed test result and return the expected result
/// as a string /// as a string
pub fn read_compressed_test_result(suffix: &str) -> String { pub fn read_compressed_test_result(suffix: &str) -> String {
@@ -42,7 +30,7 @@ pub fn read_compressed_test_result(suffix: &str) -> String {
.read_to_end(&mut compressed_data) .read_to_end(&mut compressed_data)
.expect("Unable to compress data"); .expect("Unable to compress data");
decompress_to_string(&compressed_data).unwrap() TestCompression::decompress_to_string(&compressed_data).unwrap()
} }
pub fn load_compressed_result(suffix: &str) -> String { pub fn load_compressed_result(suffix: &str) -> String {
@@ -50,39 +38,5 @@ pub fn load_compressed_result(suffix: &str) -> String {
} }
pub fn load_rom(to_load: &str) -> Vec<u8> { pub fn load_rom(to_load: &str) -> Vec<u8> {
std::fs::read(format!("../resources/roms/{}.ch8", to_load)).unwrap() std::fs::read(format!("{}{}.ch8", TEST_ROMS_SAMPLE_DIR, to_load)).unwrap()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
assert!(true)
}
#[test]
fn compression_round_trip() {
let to_compress = "The quick brown fox jumps over the lazy dog.";
let compressed_text = compress_string(to_compress);
let decompressed_text = decompress_to_string(&compressed_text).unwrap();
assert_eq!(to_compress, decompressed_text);
}
#[test]
fn file_compression_round_trip() {
// compress string to file...
let string_to_compress = "The quick brown fox jumps over the lazy dog.";
let compressed_string = compress_string(string_to_compress);
let temp_target = tempfile().unwrap();
//
// ...decompress from file...
//
// ...verify its the same.
}
} }
+25
View File
@@ -0,0 +1,25 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][!!!! CONTROLS !!!!]
Pos=8,21
Size=298,569
Collapsed=0
[Window][Keypad]
Pos=1057,32
Size=76,99
Collapsed=0
[Window][Video]
Pos=321,4
Size=800,600
Collapsed=0
[Window][System Memory]
Pos=768,2
Size=385,600
Collapsed=0
@@ -0,0 +1 @@
{"num_cycles":0,"memory":{"memory":[240,144,144,144,240,32,96,32,32,112,240,16,240,128,240,240,16,240,16,240,144,144,240,16,16,240,128,240,16,240,240,128,240,144,240,240,16,32,64,64,240,144,240,144,240,240,144,240,16,240,240,144,240,144,144,224,144,224,144,224,240,128,128,128,240,224,144,144,144,224,240,128,240,128,240,240,128,240,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,144,144,144,144,144,144,144,144,240,32,96,160,32,32,32,32,32,32,112,240,16,16,16,240,128,128,128,128,240,240,16,16,16,240,16,16,16,16,240,144,144,144,144,240,16,16,16,16,16,240,128,128,128,240,16,16,16,16,240,240,128,128,128,240,144,144,144,144,240,240,16,16,16,16,16,16,16,16,16,240,144,144,144,240,144,144,144,144,240,240,144,144,144,240,16,16,16,16,240,240,144,144,144,240,144,144,144,144,144,224,144,144,144,224,144,144,144,144,224,240,128,128,128,128,128,128,128,128,240,224,144,144,144,144,144,144,144,144,224,240,128,128,128,240,128,128,128,128,240,240,128,128,128,240,128,128,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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