Add travis config, fix tests.

This commit is contained in:
Kyle Isom 2015-12-17 02:00:45 -08:00
parent e27a6fed94
commit 5eb7246220
6 changed files with 42 additions and 20 deletions

15
.travis.yml Normal file
View File

@ -0,0 +1,15 @@
language: cpp
compiler:
- clang
- gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- clang
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
script: ./autobuild

View File

@ -3,4 +3,5 @@
CXX=g++ CXX=g++
command -v clang 2>&1 > /dev/null && CXX=clang++ command -v clang 2>&1 > /dev/null && CXX=clang++
[ -d m4 ] || mkdir m4 [ -d m4 ] || mkdir m4
autoreconf -i && ./configure CXX=$CXX && make && make check autoreconf -i && ./configure --enable-silent-rules CXX=$CXX \
&& make && make check

View File

@ -1,10 +1,10 @@
AC_PREREQ([2.69]) AC_PREREQ([2.68])
AC_INIT([libemsha], AC_INIT([libemsha],
[1.0.0-RC1], [1.0.0-RC1],
[coder@kyleisom.net], [coder@kyleisom.net],
[libemsha], [libemsha],
[https://kyleisom.net/projects/libemsha/]) [https://kyleisom.net/projects/libemsha/])
AM_INIT_AUTOMAKE([1.14 foreign]) AM_INIT_AUTOMAKE([1.11 foreign])
AC_CONFIG_SRCDIR([src/emsha/sha256.hh]) AC_CONFIG_SRCDIR([src/emsha/sha256.hh])
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile doc/sphinx/source/conf.py]) AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile doc/sphinx/source/conf.py])

View File

@ -78,10 +78,13 @@ hash_equal_test(void)
} }
if (!(emsha::hash_equal(a, b))) { if (!(emsha::hash_equal(a, b))) {
string s;
cerr << "FAILED: hash_equal\n"; cerr << "FAILED: hash_equal\n";
cerr << "\thash_equal should have succeeded comparing a and b.\n"; cerr << "\thash_equal should have succeeded comparing a and b.\n";
cerr << "\ta <- " << dump_hexstring(a, emsha::SHA256_HASH_SIZE) << std::endl; dump_hexstring(s, a, emsha::SHA256_HASH_SIZE);
cerr << "\tb <- " << dump_hexstring(b, emsha::SHA256_HASH_SIZE) << std::endl; cerr << "\ta <- " << s << std::endl;
dump_hexstring(s, b, emsha::SHA256_HASH_SIZE);
cerr << "\tb <- " << s << std::endl;
exit(1); exit(1);
} }
@ -91,10 +94,13 @@ hash_equal_test(void)
} }
if (emsha::hash_equal(a, b)) { if (emsha::hash_equal(a, b)) {
string s;
cerr << "FAILED: hash_equal\n"; cerr << "FAILED: hash_equal\n";
cerr << "\thash_equal should not have succeeded comparing a and b.\n"; cerr << "\thash_equal should not have succeeded comparing a and b.\n";
cerr << "\ta <- " << dump_hexstring(a, emsha::SHA256_HASH_SIZE) << std::endl; dump_hexstring(s, a, emsha::SHA256_HASH_SIZE);
cerr << "\tb <- " << dump_hexstring(b, emsha::SHA256_HASH_SIZE) << std::endl; cerr << "\ta <- " << s << std::endl;
dump_hexstring(s, b, emsha::SHA256_HASH_SIZE);
cerr << "\tb <- " << s << std::endl;
exit(1); exit(1);
} }

View File

@ -38,18 +38,18 @@ using std::cerr;
using std::endl; using std::endl;
string void
dump_hexstring(uint8_t *s, uint32_t sl) dump_hexstring(string& hs, uint8_t *s, uint32_t sl)
{ {
uint32_t bl = (2 * sl) + 1; uint32_t bl = (2 * sl) + 1;
char *buf = new char[bl]; char *buf = new char[bl];
string hs; string tmp;
memset(buf, 0, bl); memset(buf, 0, bl);
emsha::hexstring((uint8_t *)buf, s, sl); emsha::hexstring((uint8_t *)buf, s, sl);
hs = string(buf); tmp = string(buf);
hs.swap(tmp);
delete[] buf; delete[] buf;
return hs;
} }
@ -72,7 +72,7 @@ run_hmac_test(struct hmac_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;
goto exit; goto exit;
@ -94,7 +94,7 @@ run_hmac_test(struct hmac_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;
goto exit; goto exit;
@ -111,7 +111,7 @@ run_hmac_test(struct hmac_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
cerr << "(comparing single pass function output)\n"; cerr << "(comparing single pass function output)\n";
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;
@ -165,7 +165,7 @@ run_hash_test(struct hash_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;
goto exit; goto exit;
@ -187,7 +187,7 @@ run_hash_test(struct hash_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;
goto exit; goto exit;
@ -203,7 +203,7 @@ run_hash_test(struct hash_test test, string label)
goto exit; goto exit;
} }
hs = dump_hexstring(dig, emsha::SHA256_HASH_SIZE); dump_hexstring(hs, dig, emsha::SHA256_HASH_SIZE);
if (hs != test.output) { if (hs != test.output) {
cerr << "(comparing single pass function output)\n"; cerr << "(comparing single pass function output)\n";
res = emsha::EMSHA_TEST_FAILURE; res = emsha::EMSHA_TEST_FAILURE;

View File

@ -59,7 +59,7 @@ struct hmac_test {
// General-purpose debuggery. // General-purpose debuggery.
std::string dump_hexstring(std::uint8_t *, std::uint32_t); void dump_hexstring(std::string&, std::uint8_t *, std::uint32_t);
void dump_pair(std::uint8_t *, std::uint8_t *); void dump_pair(std::uint8_t *, std::uint8_t *);