Skip to content

Commit

Permalink
Embed test data into test executables.
Browse files Browse the repository at this point in the history
Embed test data files into test executables so that file I/O isn't
necessary during tests. This allows the tests to run on platforms that
don't have file I/O. It also makes it easier to run the tests on a
separate (virtual) machine from the build machine since the test
automation no longer needs to keep track of the test files.
  • Loading branch information
briansmith committed Feb 2, 2019
1 parent 8df1463 commit ab0726d
Show file tree
Hide file tree
Showing 25 changed files with 538 additions and 537 deletions.
12 changes: 0 additions & 12 deletions mk/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,9 @@ armv7-linux-androideabi)

find $target_dir -maxdepth 1 -name ring-* ! -name "*.*" \
-exec adb push {} /data/ring-test \;
for testfile in `find src crypto -name "*_test*.txt" -o -name "*test*.pk8"`; do
adb shell "mkdir -p /data/`dirname $testfile`"
adb push $testfile /data/$testfile
done
adb shell "mkdir -p /data/third_party/NIST"
adb push third_party/NIST/SHAVS /data/third_party/NIST/SHAVS
adb shell "cd /data && ./ring-test" 2>&1 | tee /tmp/ring-test-log
grep "test result: ok" /tmp/ring-test-log

# Run the integration/functional tests.
for testfile in `find tests -name "*_test*.txt" -o -name "*test*.pk8"`; do
adb shell "mkdir -p /data/`dirname $testfile`"
adb push $testfile /data/$testfile
done

for test_exe in `find $target_dir -maxdepth 1 -name "*test*" -type f ! -name "*.*" `; do
adb push $test_exe /data/`basename $test_exe`
adb shell "cd /data && ./`basename $test_exe`" 2>&1 | \
Expand Down
2 changes: 1 addition & 1 deletion src/aead/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ mod tests {

#[test]
pub fn test_aes() {
test::from_file("src/aead/aes_tests.txt", |section, test_case| {
test::run(test_file!("aes_tests.txt"), |section, test_case| {
assert_eq!(section, "");
let key = consume_key(test_case, "Key");
let input = test_case.consume_bytes("Input");
Expand Down
2 changes: 1 addition & 1 deletion src/aead/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod tests {
// problem spreads to other platforms.
#[test]
pub fn chacha20_tests() {
test::from_file("src/aead/chacha_tests.txt", |section, test_case| {
test::run(test_file!("chacha_tests.txt"), |section, test_case| {
assert_eq!(section, "");

let key = test_case.consume_bytes("Key");
Expand Down
2 changes: 1 addition & 1 deletion src/aead/poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ mod tests {
// Adapted from BoringSSL's crypto/poly1305/poly1305_test.cc.
#[test]
pub fn test_poly1305() {
test::from_file("src/aead/poly1305_test.txt", |section, test_case| {
test::run(test_file!("poly1305_test.txt"), |section, test_case| {
assert_eq!(section, "");
let key = test_case.consume_bytes("Key");
let key: &[u8; BLOCK_LEN * 2] = key.as_slice().try_into_().unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/bssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ macro_rules! bssl_test {
}

let _ = cpu::features();
::std::env::set_current_dir(crate::test::ring_src_path()).unwrap();

let result = unsafe { $bssl_test_main_fn_name() };
assert_eq!(result, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/ec/suite_b/ecdsa/digest_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ mod tests {

#[test]
fn test() {
test::from_file(
"src/ec/suite_b/ecdsa/ecdsa_digest_scalar_tests.txt",
test::run(
test_file!("ecdsa_digest_scalar_tests.txt"),
|section, test_case| {
assert_eq!(section, "");

Expand Down
8 changes: 4 additions & 4 deletions src/ec/suite_b/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ mod tests {

#[test]
fn signature_ecdsa_sign_fixed_test() {
test::from_file(
"src/ec/suite_b/ecdsa/ecdsa_sign_fixed_tests.txt",
test::run(
test_file!("ecdsa_sign_fixed_tests.txt"),
|section, test_case| {
assert_eq!(section, "");

Expand Down Expand Up @@ -431,8 +431,8 @@ mod tests {

#[test]
fn signature_ecdsa_sign_asn1_test() {
test::from_file(
"src/ec/suite_b/ecdsa/ecdsa_sign_asn1_tests.txt",
test::run(
test_file!("ecdsa_sign_asn1_tests.txt"),
|section, test_case| {
assert_eq!(section, "");

Expand Down
4 changes: 2 additions & 2 deletions src/ec/suite_b/ecdsa/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ mod tests {

#[test]
fn test_digest_based_test_vectors() {
test::from_file(
"crypto/fipsmodule/ecdsa/ecdsa_verify_tests.txt",
test::run(
test_file!("../../../../crypto/fipsmodule/ecdsa/ecdsa_verify_tests.txt"),
|section, test_case| {
assert_eq!(section, "");

Expand Down
Loading

0 comments on commit ab0726d

Please sign in to comment.