[FFmpeg-devel] [PATCH] Add tests for functions in hash.c

NagaChaitanya Vellanki nagachaitanya.vellanki at gmail.com
Mon Mar 7 04:26:27 CET 2016


---
 libavutil/Makefile       |  1 +
 libavutil/hash.c         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak |  4 ++++
 tests/ref/fate/hash      | 45 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 tests/ref/fate/hash

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 934564f..58df75a 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -186,6 +186,7 @@ TESTPROGS = adler32                                                     \
             file                                                        \
             fifo                                                        \
             float_dsp                                                   \
+            hash                                                        \
             hmac                                                        \
             lfg                                                         \
             lls                                                         \
diff --git a/libavutil/hash.c b/libavutil/hash.c
index 7037b0d..ac35e88 100644
--- a/libavutil/hash.c
+++ b/libavutil/hash.c
@@ -237,3 +237,48 @@ void av_hash_freep(AVHashContext **ctx)
         av_freep(&(*ctx)->ctx);
     av_freep(ctx);
 }
+
+#ifdef TEST
+// LCOV_EXCL_START
+#define SRC_BUF_SIZE 64
+#define DST_BUF_SIZE 512
+
+int main(void)
+{
+   struct AVHashContext *ctx = NULL;
+   int i, j;
+   static const uint8_t src[SRC_BUF_SIZE] = { 0 };
+   uint8_t dst[DST_BUF_SIZE];
+   for(i = 0; i < NUM_HASHES; i++) {
+       if(av_hash_alloc(&ctx, av_hash_names(i)) < 0) {
+           return 1;
+       }
+
+       av_hash_init(ctx);
+       av_hash_update(ctx, src, SRC_BUF_SIZE);
+       memset(dst, 0, DST_BUF_SIZE);
+       av_hash_final_hex(ctx, dst, DST_BUF_SIZE);
+       printf("%s hex: %s\n", av_hash_get_name(ctx), dst);
+
+       av_hash_init(ctx);
+       av_hash_update(ctx, src, SRC_BUF_SIZE);
+       memset(dst, 0, DST_BUF_SIZE);
+       av_hash_final_bin(ctx, dst, DST_BUF_SIZE);
+       printf("%s bin: ", av_hash_get_name(ctx));
+       for(j = 0; j < av_hash_get_size(ctx); j++) {
+         printf("%#x ", dst[j]);
+       }
+       printf("\n");
+
+       av_hash_init(ctx);
+       av_hash_update(ctx, src, SRC_BUF_SIZE);
+       memset(dst, 0, DST_BUF_SIZE);
+       av_hash_final_b64(ctx, dst, DST_BUF_SIZE);
+       printf("%s b64: %s\n", av_hash_get_name(ctx), dst);
+       av_hash_freep(&ctx);
+   }
+   return 0;
+}
+
+// LCOV_EXCL_STOP
+#endif
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index a89bc1d..5d8e0e2 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -75,6 +75,10 @@ fate-float-dsp: CMD = run libavutil/float_dsp-test $(CPUFLAGS:%=-c%)
 fate-float-dsp: CMP = null
 fate-float-dsp: REF = /dev/null
 
+FATE_LIBAVUTIL += fate-hash
+fate-hash: libavutil/hash-test$(EXESUF)
+fate-hash: CMD = run libavutil/hash-test
+
 FATE_LIBAVUTIL += fate-hmac
 fate-hmac: libavutil/hmac-test$(EXESUF)
 fate-hmac: CMD = run libavutil/hmac-test
diff --git a/tests/ref/fate/hash b/tests/ref/fate/hash
new file mode 100644
index 0000000..6e5a580
--- /dev/null
+++ b/tests/ref/fate/hash
@@ -0,0 +1,45 @@
+MD5 hex: 3b5d3c7d207e37dceeedd301e35e2e58
+MD5 bin: 0x3b 0x5d 0x3c 0x7d 0x20 0x7e 0x37 0xdc 0xee 0xed 0xd3 0x1 0xe3 0x5e 0x2e 0x58
+MD5 b64: O108fSB+N9zu7dMB414uWA==
+murmur3 hex: 6e484695e1d7b4e37d838791cc263395
+murmur3 bin: 0x6e 0x48 0x46 0x95 0xe1 0xd7 0xb4 0xe3 0x7d 0x83 0x87 0x91 0xcc 0x26 0x33 0x95
+murmur3 b64: bkhGleHXtON9g4eRzCYzlQ==
+RIPEMD128 hex: 082bfa9b829ef3a9e220dcc54e4c6383
+RIPEMD128 bin: 0x8 0x2b 0xfa 0x9b 0x82 0x9e 0xf3 0xa9 0xe2 0x20 0xdc 0xc5 0x4e 0x4c 0x63 0x83
+RIPEMD128 b64: CCv6m4Ke86niINzFTkxjgw==
+RIPEMD160 hex: 9b8ccc2f374ae313a914763cc9cdfb47bfe1c229
+RIPEMD160 bin: 0x9b 0x8c 0xcc 0x2f 0x37 0x4a 0xe3 0x13 0xa9 0x14 0x76 0x3c 0xc9 0xcd 0xfb 0x47 0xbf 0xe1 0xc2 0x29
+RIPEMD160 b64: m4zMLzdK4xOpFHY8yc37R7/hwik=
+RIPEMD256 hex: 26ba693759787f275f47dd5ab16e78c2fcd763b004fd05fc554e354223d6eab5
+RIPEMD256 bin: 0x26 0xba 0x69 0x37 0x59 0x78 0x7f 0x27 0x5f 0x47 0xdd 0x5a 0xb1 0x6e 0x78 0xc2 0xfc 0xd7 0x63 0xb0 0x4 0xfd 0x5 0xfc 0x55 0x4e 0x35 0x42 0x23 0xd6 0xea 0xb5
+RIPEMD256 b64: JrppN1l4fydfR91asW54wvzXY7AE/QX8VU41QiPW6rU=
+RIPEMD320 hex: 409a3111ffd3d4c8058ff5c231401c1d47210a5d22e6c90bf95d45c1c95c528463c69ce4bff3b884
+RIPEMD320 bin: 0x40 0x9a 0x31 0x11 0xff 0xd3 0xd4 0xc8 0x5 0x8f 0xf5 0xc2 0x31 0x40 0x1c 0x1d 0x47 0x21 0xa 0x5d 0x22 0xe6 0xc9 0xb 0xf9 0x5d 0x45 0xc1 0xc9 0x5c 0x52 0x84 0x63 0xc6 0x9c 0xe4 0xbf 0xf3 0xb8 0x84
+RIPEMD320 b64: QJoxEf/T1MgFj/XCMUAcHUchCl0i5skL+V1FwclcUoRjxpzkv/O4hA==
+SHA160 hex: c8d7d0ef0eedfa82d2ea1aa592845b9a6d4b02b7
+SHA160 bin: 0xc8 0xd7 0xd0 0xef 0xe 0xed 0xfa 0x82 0xd2 0xea 0x1a 0xa5 0x92 0x84 0x5b 0x9a 0x6d 0x4b 0x2 0xb7
+SHA160 b64: yNfQ7w7t+oLS6hqlkoRbmm1LArc=
+SHA224 hex: 750d81a39c18d3ce27ff3e5ece30b0088f12d8fd0450fe435326294b
+SHA224 bin: 0x75 0xd 0x81 0xa3 0x9c 0x18 0xd3 0xce 0x27 0xff 0x3e 0x5e 0xce 0x30 0xb0 0x8 0x8f 0x12 0xd8 0xfd 0x4 0x50 0xfe 0x43 0x53 0x26 0x29 0x4b
+SHA224 b64: dQ2Bo5wY084n/z5ezjCwCI8S2P0EUP5DUyYpSw==
+SHA256 hex: f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b
+SHA256 bin: 0xf5 0xa5 0xfd 0x42 0xd1 0x6a 0x20 0x30 0x27 0x98 0xef 0x6e 0xd3 0x9 0x97 0x9b 0x43 0 0x3d 0x23 0x20 0xd9 0xf0 0xe8 0xea 0x98 0x31 0xa9 0x27 0x59 0xfb 0x4b
+SHA256 b64: 9aX9QtFqIDAnmO9u0wmXm0MAPSMg2fDo6pgxqSdZ+0s=
+SHA512/224 hex: 1319d9b322452068e6f43c0ed3da115fbeccc169711dbbaee2846f90
+SHA512/224 bin: 0x13 0x19 0xd9 0xb3 0x22 0x45 0x20 0x68 0xe6 0xf4 0x3c 0xe 0xd3 0xda 0x11 0x5f 0xbe 0xcc 0xc1 0x69 0x71 0x1d 0xbb 0xae 0xe2 0x84 0x6f 0x90
+SHA512/224 b64: ExnZsyJFIGjm9DwO09oRX77MwWlxHbuu4oRvkA==
+SHA512/256 hex: 8aeecfa0b9f2ac7818863b1362241e4f32d06b100ae9d1c0fbcc4ed61b91b17a
+SHA512/256 bin: 0x8a 0xee 0xcf 0xa0 0xb9 0xf2 0xac 0x78 0x18 0x86 0x3b 0x13 0x62 0x24 0x1e 0x4f 0x32 0xd0 0x6b 0x10 0xa 0xe9 0xd1 0xc0 0xfb 0xcc 0x4e 0xd6 0x1b 0x91 0xb1 0x7a
+SHA512/256 b64: iu7PoLnyrHgYhjsTYiQeTzLQaxAK6dHA+8xO1huRsXo=
+SHA384 hex: c516aa8d3b457c636c6826937099c0d23a13f2c3701a388b3c8fe4bc2073281b0c4462610369884c4ababa8e97b6debe
+SHA384 bin: 0xc5 0x16 0xaa 0x8d 0x3b 0x45 0x7c 0x63 0x6c 0x68 0x26 0x93 0x70 0x99 0xc0 0xd2 0x3a 0x13 0xf2 0xc3 0x70 0x1a 0x38 0x8b 0x3c 0x8f 0xe4 0xbc 0x20 0x73 0x28 0x1b 0xc 0x44 0x62 0x61 0x3 0x69 0x88 0x4c 0x4a 0xba 0xba 0x8e 0x97 0xb6 0xde 0xbe
+SHA384 b64: xRaqjTtFfGNsaCaTcJnA0joT8sNwGjiLPI/kvCBzKBsMRGJhA2mITEq6uo6Xtt6+
+SHA512 hex: 7be9fda48f4179e611c698a73cff09faf72869431efee6eaad14de0cb44bbf66503f752b7a8eb17083355f3ce6eb7d2806f236b25af96a24e22b887405c20081
+SHA512 bin: 0x7b 0xe9 0xfd 0xa4 0x8f 0x41 0x79 0xe6 0x11 0xc6 0x98 0xa7 0x3c 0xff 0x9 0xfa 0xf7 0x28 0x69 0x43 0x1e 0xfe 0xe6 0xea 0xad 0x14 0xde 0xc 0xb4 0x4b 0xbf 0x66 0x50 0x3f 0x75 0x2b 0x7a 0x8e 0xb1 0x70 0x83 0x35 0x5f 0x3c 0xe6 0xeb 0x7d 0x28 0x6 0xf2 0x36 0xb2 0x5a 0xf9 0x6a 0x24 0xe2 0x2b 0x88 0x74 0x5 0xc2 0 0x81
+SHA512 b64: e+n9pI9BeeYRxpinPP8J+vcoaUMe/ubqrRTeDLRLv2ZQP3Ureo6xcIM1Xzzm630oBvI2slr5aiTiK4h0BcIAgQ==
+CRC32 hex: 758d6336
+CRC32 bin: 0x75 0x8d 0x63 0x36
+CRC32 b64: dY1jNg==
+adler32 hex: 00400001
+adler32 bin: 0 0x40 0 0x1
+adler32 b64: AEAAAQ==
-- 
2.5.0



More information about the ffmpeg-devel mailing list