Test: Mark compilation-unit-only functions as static

This enables a nice warning in case a function becomes dead code. Also,
in the case of test-crypto.cpp, I took the liberty to add the prefix 'g_'
to the global event loop.
This commit is contained in:
Ben Wiederhake 2020-08-11 00:02:25 +02:00 committed by Andreas Kling
parent 2b76f48a17
commit 76da9a4a7d
Notes: sideshowbarker 2024-07-19 03:42:41 +09:00
9 changed files with 191 additions and 192 deletions

View file

@ -42,7 +42,7 @@ struct worker_t {
long int wait_time; long int wait_time;
}; };
void* run_worker(void* args) static void* run_worker(void* args)
{ {
struct timespec time_to_wait = { 0, 0 }; struct timespec time_to_wait = { 0, 0 };
worker_t* worker = (worker_t*)args; worker_t* worker = (worker_t*)args;
@ -65,7 +65,7 @@ void* run_worker(void* args)
return nullptr; return nullptr;
} }
void init_worker(worker_t* worker, const char* name, long int wait_time) static void init_worker(worker_t* worker, const char* name, long int wait_time)
{ {
worker->name = name; worker->name = name;
worker->wait_time = wait_time; worker->wait_time = wait_time;

View file

@ -256,7 +256,7 @@ constexpr size_t NUM_TESTCASES = sizeof(TESTCASES) / sizeof(TESTCASES[0]);
typedef double (*strtod_fn_t)(const char* str, char** endptr); typedef double (*strtod_fn_t)(const char* str, char** endptr);
long long cast_ll(double d) static long long cast_ll(double d)
{ {
union readable_t { union readable_t {
double as_double; double as_double;
@ -273,7 +273,7 @@ long long cast_ll(double d)
return readable.as_ll; return readable.as_ll;
} }
bool is_strtod_close(strtod_fn_t strtod_fn, const char* test_string, const char* expect_hex, int expect_consume, long long expect_ll) static bool is_strtod_close(strtod_fn_t strtod_fn, const char* test_string, const char* expect_hex, int expect_consume, long long expect_ll)
{ {
union readable_t { union readable_t {
double as_double; double as_double;
@ -324,7 +324,7 @@ bool is_strtod_close(strtod_fn_t strtod_fn, const char* test_string, const char*
return !(wrong_hex || error_cns || wrong_cns); return !(wrong_hex || error_cns || wrong_cns);
} }
long long hex_to_ll(const char* hex) static long long hex_to_ll(const char* hex)
{ {
long long result = 0; long long result = 0;
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {

View file

@ -37,7 +37,7 @@ struct SortableObject {
int m_payload; int m_payload;
}; };
int compare_sortable_object(const void* a, const void* b) static int compare_sortable_object(const void* a, const void* b)
{ {
const int key1 = static_cast<const SortableObject*>(a)->m_key; const int key1 = static_cast<const SortableObject*>(a)->m_key;
const int key2 = static_cast<const SortableObject*>(b)->m_key; const int key2 = static_cast<const SortableObject*>(b)->m_key;
@ -50,13 +50,13 @@ int compare_sortable_object(const void* a, const void* b)
} }
} }
int calc_payload_for_pos(size_t pos) static int calc_payload_for_pos(size_t pos)
{ {
pos *= 231; pos *= 231;
return pos ^ (pos << 8) ^ (pos << 16) ^ (pos << 24); return pos ^ (pos << 8) ^ (pos << 16) ^ (pos << 24);
} }
void shuffle_vec(Vector<SortableObject>& test_objects) static void shuffle_vec(Vector<SortableObject>& test_objects)
{ {
for (size_t i = 0; i < test_objects.size() * 3; ++i) { for (size_t i = 0; i < test_objects.size() * 3; ++i) {
auto i1 = rand() % test_objects.size(); auto i1 = rand() % test_objects.size();

View file

@ -33,12 +33,12 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
void test_invalid(int); static void test_invalid(int);
void test_no_route(int); static void test_no_route(int);
void test_valid(int); static void test_valid(int);
void test_send(int); static void test_send(int);
void test(AK::Function<void(int)> test_fn) static void test(AK::Function<void(int)> test_fn)
{ {
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

View file

@ -70,36 +70,36 @@ constexpr const char* DEFAULT_SERVER { "www.google.com" };
// listAllTests // listAllTests
// Cipher // Cipher
int aes_cbc_tests(); static int aes_cbc_tests();
int aes_ctr_tests(); static int aes_ctr_tests();
// Hash // Hash
int md5_tests(); static int md5_tests();
int sha1_tests(); static int sha1_tests();
int sha256_tests(); static int sha256_tests();
int sha512_tests(); static int sha512_tests();
// Authentication // Authentication
int hmac_md5_tests(); static int hmac_md5_tests();
int hmac_sha256_tests(); static int hmac_sha256_tests();
int hmac_sha512_tests(); static int hmac_sha512_tests();
// Public-Key // Public-Key
int rsa_tests(); static int rsa_tests();
// TLS // TLS
int tls_tests(); static int tls_tests();
// Big Integer // Big Integer
int bigint_tests(); static int bigint_tests();
// Checksum // Checksum
int adler32_tests(); static int adler32_tests();
int crc32_tests(); static int crc32_tests();
// stop listing tests // stop listing tests
void print_buffer(const ReadonlyBytes& buffer, int split) static void print_buffer(const ReadonlyBytes& buffer, int split)
{ {
for (size_t i = 0; i < buffer.size(); ++i) { for (size_t i = 0; i < buffer.size(); ++i) {
if (split > 0) { if (split > 0) {
@ -117,8 +117,9 @@ void print_buffer(const ReadonlyBytes& buffer, int split)
puts(""); puts("");
} }
Core::EventLoop loop; static Core::EventLoop g_loop;
int run(Function<void(const char*, size_t)> fn)
static int run(Function<void(const char*, size_t)> fn)
{ {
if (interactive) { if (interactive) {
auto editor = Line::Editor::construct(); auto editor = Line::Editor::construct();
@ -131,10 +132,10 @@ int run(Function<void(const char*, size_t)> fn)
auto& line = line_result.value(); auto& line = line_result.value();
if (line == ".wait") { if (line == ".wait") {
loop.exec(); g_loop.exec();
} else { } else {
fn(line.characters(), line.length()); fn(line.characters(), line.length());
loop.pump(); g_loop.pump();
} }
} }
} else { } else {
@ -153,12 +154,12 @@ int run(Function<void(const char*, size_t)> fn)
} }
auto buffer = file.value()->read_all(); auto buffer = file.value()->read_all();
fn((const char*)buffer.data(), buffer.size()); fn((const char*)buffer.data(), buffer.size());
loop.exec(); g_loop.exec();
} }
return 0; return 0;
} }
void tls(const char* message, size_t len) static void tls(const char* message, size_t len)
{ {
static RefPtr<TLS::TLSv12> tls; static RefPtr<TLS::TLSv12> tls;
static ByteBuffer write {}; static ByteBuffer write {};
@ -177,17 +178,17 @@ void tls(const char* message, size_t len)
} }
}; };
tls->on_tls_error = [&](auto) { tls->on_tls_error = [&](auto) {
loop.quit(1); g_loop.quit(1);
}; };
tls->on_tls_finished = [&]() { tls->on_tls_finished = [&]() {
loop.quit(0); g_loop.quit(0);
}; };
} }
write.append(message, len); write.append(message, len);
write.append("\r\n", 2); write.append("\r\n", 2);
} }
void aes_cbc(const char* message, size_t len) static void aes_cbc(const char* message, size_t len)
{ {
auto buffer = ByteBuffer::wrap(const_cast<char*>(message), len); auto buffer = ByteBuffer::wrap(const_cast<char*>(message), len);
// FIXME: Take iv as an optional parameter // FIXME: Take iv as an optional parameter
@ -219,19 +220,19 @@ void aes_cbc(const char* message, size_t len)
} }
} }
void adler32(const char* message, size_t len) static void adler32(const char* message, size_t len)
{ {
auto checksum = Crypto::Checksum::Adler32({ (const u8*)message, len }); auto checksum = Crypto::Checksum::Adler32({ (const u8*)message, len });
printf("%#10X\n", checksum.digest()); printf("%#10X\n", checksum.digest());
} }
void crc32(const char* message, size_t len) static void crc32(const char* message, size_t len)
{ {
auto checksum = Crypto::Checksum::CRC32({ (const u8*)message, len }); auto checksum = Crypto::Checksum::CRC32({ (const u8*)message, len });
printf("%#10X\n", checksum.digest()); printf("%#10X\n", checksum.digest());
} }
void md5(const char* message, size_t len) static void md5(const char* message, size_t len)
{ {
auto digest = Crypto::Hash::MD5::hash((const u8*)message, len); auto digest = Crypto::Hash::MD5::hash((const u8*)message, len);
if (binary) if (binary)
@ -240,7 +241,7 @@ void md5(const char* message, size_t len)
print_buffer({ digest.data, Crypto::Hash::MD5::digest_size() }, -1); print_buffer({ digest.data, Crypto::Hash::MD5::digest_size() }, -1);
} }
void hmac_md5(const char* message, size_t len) static void hmac_md5(const char* message, size_t len)
{ {
Crypto::Authentication::HMAC<Crypto::Hash::MD5> hmac(secret_key); Crypto::Authentication::HMAC<Crypto::Hash::MD5> hmac(secret_key);
auto mac = hmac.process((const u8*)message, len); auto mac = hmac.process((const u8*)message, len);
@ -250,7 +251,7 @@ void hmac_md5(const char* message, size_t len)
print_buffer({ mac.data, hmac.digest_size() }, -1); print_buffer({ mac.data, hmac.digest_size() }, -1);
} }
void sha1(const char* message, size_t len) static void sha1(const char* message, size_t len)
{ {
auto digest = Crypto::Hash::SHA1::hash((const u8*)message, len); auto digest = Crypto::Hash::SHA1::hash((const u8*)message, len);
if (binary) if (binary)
@ -259,7 +260,7 @@ void sha1(const char* message, size_t len)
print_buffer({ digest.data, Crypto::Hash::SHA1::digest_size() }, -1); print_buffer({ digest.data, Crypto::Hash::SHA1::digest_size() }, -1);
} }
void sha256(const char* message, size_t len) static void sha256(const char* message, size_t len)
{ {
auto digest = Crypto::Hash::SHA256::hash((const u8*)message, len); auto digest = Crypto::Hash::SHA256::hash((const u8*)message, len);
if (binary) if (binary)
@ -268,7 +269,7 @@ void sha256(const char* message, size_t len)
print_buffer({ digest.data, Crypto::Hash::SHA256::digest_size() }, -1); print_buffer({ digest.data, Crypto::Hash::SHA256::digest_size() }, -1);
} }
void hmac_sha256(const char* message, size_t len) static void hmac_sha256(const char* message, size_t len)
{ {
Crypto::Authentication::HMAC<Crypto::Hash::SHA256> hmac(secret_key); Crypto::Authentication::HMAC<Crypto::Hash::SHA256> hmac(secret_key);
auto mac = hmac.process((const u8*)message, len); auto mac = hmac.process((const u8*)message, len);
@ -278,7 +279,7 @@ void hmac_sha256(const char* message, size_t len)
print_buffer({ mac.data, hmac.digest_size() }, -1); print_buffer({ mac.data, hmac.digest_size() }, -1);
} }
void sha512(const char* message, size_t len) static void sha512(const char* message, size_t len)
{ {
auto digest = Crypto::Hash::SHA512::hash((const u8*)message, len); auto digest = Crypto::Hash::SHA512::hash((const u8*)message, len);
if (binary) if (binary)
@ -287,7 +288,7 @@ void sha512(const char* message, size_t len)
print_buffer({ digest.data, Crypto::Hash::SHA512::digest_size() }, -1); print_buffer({ digest.data, Crypto::Hash::SHA512::digest_size() }, -1);
} }
void hmac_sha512(const char* message, size_t len) static void hmac_sha512(const char* message, size_t len)
{ {
Crypto::Authentication::HMAC<Crypto::Hash::SHA512> hmac(secret_key); Crypto::Authentication::HMAC<Crypto::Hash::SHA512> hmac(secret_key);
auto mac = hmac.process((const u8*)message, len); auto mac = hmac.process((const u8*)message, len);
@ -496,7 +497,7 @@ auto main(int argc, char** argv) -> int
g_some_test_failed = true; \ g_some_test_failed = true; \
} while (0) } while (0)
ByteBuffer operator""_b(const char* string, size_t length) static ByteBuffer operator""_b(const char* string, size_t length)
{ {
dbg() << "Create byte buffer of size " << length; dbg() << "Create byte buffer of size " << length;
return ByteBuffer::copy(string, length); return ByteBuffer::copy(string, length);
@ -504,62 +505,62 @@ ByteBuffer operator""_b(const char* string, size_t length)
// tests go after here // tests go after here
// please be reasonable with orders kthx // please be reasonable with orders kthx
void aes_cbc_test_name(); static void aes_cbc_test_name();
void aes_cbc_test_encrypt(); static void aes_cbc_test_encrypt();
void aes_cbc_test_decrypt(); static void aes_cbc_test_decrypt();
void aes_ctr_test_name(); static void aes_ctr_test_name();
void aes_ctr_test_encrypt(); static void aes_ctr_test_encrypt();
void aes_ctr_test_decrypt(); static void aes_ctr_test_decrypt();
void md5_test_name(); static void md5_test_name();
void md5_test_hash(); static void md5_test_hash();
void md5_test_consecutive_updates(); static void md5_test_consecutive_updates();
void sha1_test_name(); static void sha1_test_name();
void sha1_test_hash(); static void sha1_test_hash();
void sha256_test_name(); static void sha256_test_name();
void sha256_test_hash(); static void sha256_test_hash();
void sha512_test_name(); static void sha512_test_name();
void sha512_test_hash(); static void sha512_test_hash();
void hmac_md5_test_name(); static void hmac_md5_test_name();
void hmac_md5_test_process(); static void hmac_md5_test_process();
void hmac_sha256_test_name(); static void hmac_sha256_test_name();
void hmac_sha256_test_process(); static void hmac_sha256_test_process();
void hmac_sha512_test_name(); static void hmac_sha512_test_name();
void hmac_sha512_test_process(); static void hmac_sha512_test_process();
void rsa_test_encrypt(); static void rsa_test_encrypt();
void rsa_test_der_parse(); static void rsa_test_der_parse();
void rsa_test_encrypt_decrypt(); static void rsa_test_encrypt_decrypt();
void rsa_emsa_pss_test_create(); static void rsa_emsa_pss_test_create();
void bigint_test_number_theory(); // FIXME: we should really move these num theory stuff out static void bigint_test_number_theory(); // FIXME: we should really move these num theory stuff out
void tls_test_client_hello(); static void tls_test_client_hello();
void bigint_test_fibo500(); static void bigint_test_fibo500();
void bigint_addition_edgecases(); static void bigint_addition_edgecases();
void bigint_subtraction(); static void bigint_subtraction();
void bigint_multiplication(); static void bigint_multiplication();
void bigint_division(); static void bigint_division();
void bigint_base10(); static void bigint_base10();
void bigint_import_export(); static void bigint_import_export();
void bigint_bitwise(); static void bigint_bitwise();
void bigint_test_signed_fibo500(); static void bigint_test_signed_fibo500();
void bigint_signed_addition_edgecases(); static void bigint_signed_addition_edgecases();
void bigint_signed_subtraction(); static void bigint_signed_subtraction();
void bigint_signed_multiplication(); static void bigint_signed_multiplication();
void bigint_signed_division(); static void bigint_signed_division();
void bigint_signed_base10(); static void bigint_signed_base10();
void bigint_signed_import_export(); static void bigint_signed_import_export();
void bigint_signed_bitwise(); static void bigint_signed_bitwise();
int aes_cbc_tests() static int aes_cbc_tests()
{ {
aes_cbc_test_name(); aes_cbc_test_name();
if (encrypting) { if (encrypting) {
@ -571,7 +572,7 @@ int aes_cbc_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void aes_cbc_test_name() static void aes_cbc_test_name()
{ {
I_TEST((AES CBC class name)); I_TEST((AES CBC class name));
Crypto::Cipher::AESCipher::CBCMode cipher("WellHelloFriends"_b, 128, Crypto::Cipher::Intent::Encryption); Crypto::Cipher::AESCipher::CBCMode cipher("WellHelloFriends"_b, 128, Crypto::Cipher::Intent::Encryption);
@ -581,7 +582,7 @@ void aes_cbc_test_name()
PASS; PASS;
} }
void aes_cbc_test_encrypt() static void aes_cbc_test_encrypt()
{ {
auto test_it = [](auto& cipher, auto& result) { auto test_it = [](auto& cipher, auto& result) {
auto in = "This is a test! This is another test!"_b; auto in = "This is a test! This is another test!"_b;
@ -644,7 +645,7 @@ void aes_cbc_test_encrypt()
} }
// TODO: Test non-CMS padding options // TODO: Test non-CMS padding options
} }
void aes_cbc_test_decrypt() static void aes_cbc_test_decrypt()
{ {
auto test_it = [](auto& cipher, auto& result, auto result_len) { auto test_it = [](auto& cipher, auto& result, auto result_len) {
auto true_value = "This is a test! This is another test!"; auto true_value = "This is a test! This is another test!";
@ -698,7 +699,7 @@ void aes_cbc_test_decrypt()
// TODO: Test non-CMS padding options // TODO: Test non-CMS padding options
} }
int aes_ctr_tests() static int aes_ctr_tests()
{ {
aes_ctr_test_name(); aes_ctr_test_name();
if (encrypting) { if (encrypting) {
@ -710,7 +711,7 @@ int aes_ctr_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void aes_ctr_test_name() static void aes_ctr_test_name()
{ {
I_TEST((AES CTR class name)); I_TEST((AES CTR class name));
Crypto::Cipher::AESCipher::CTRMode cipher("WellHelloFriends"_b, 128, Crypto::Cipher::Intent::Encryption); Crypto::Cipher::AESCipher::CTRMode cipher("WellHelloFriends"_b, 128, Crypto::Cipher::Intent::Encryption);
@ -721,7 +722,7 @@ void aes_ctr_test_name()
} }
#define AS_BB(x) (ByteBuffer::wrap((x), sizeof((x)) / sizeof((x)[0]))) #define AS_BB(x) (ByteBuffer::wrap((x), sizeof((x)) / sizeof((x)[0])))
void aes_ctr_test_encrypt() static void aes_ctr_test_encrypt()
{ {
auto test_it = [](auto key, auto ivec, auto in, auto out_expected) { auto test_it = [](auto key, auto ivec, auto in, auto out_expected) {
// nonce is already included in ivec. // nonce is already included in ivec.
@ -916,7 +917,7 @@ void aes_ctr_test_encrypt()
} }
} }
void aes_ctr_test_decrypt() static void aes_ctr_test_decrypt()
{ {
auto test_it = [](auto key, auto ivec, auto in, auto out_expected) { auto test_it = [](auto key, auto ivec, auto in, auto out_expected) {
// nonce is already included in ivec. // nonce is already included in ivec.
@ -955,7 +956,7 @@ void aes_ctr_test_decrypt()
// If encryption works, then decryption works, too. // If encryption works, then decryption works, too.
} }
int md5_tests() static int md5_tests()
{ {
md5_test_name(); md5_test_name();
md5_test_hash(); md5_test_hash();
@ -963,7 +964,7 @@ int md5_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void md5_test_name() static void md5_test_name()
{ {
I_TEST((MD5 class name)); I_TEST((MD5 class name));
Crypto::Hash::MD5 md5; Crypto::Hash::MD5 md5;
@ -973,7 +974,7 @@ void md5_test_name()
PASS; PASS;
} }
void md5_test_hash() static void md5_test_hash()
{ {
{ {
I_TEST((MD5 Hashing | "Well hello friends")); I_TEST((MD5 Hashing | "Well hello friends"));
@ -1048,7 +1049,7 @@ void md5_test_hash()
} }
} }
void md5_test_consecutive_updates() static void md5_test_consecutive_updates()
{ {
{ {
I_TEST((MD5 Hashing | Multiple Updates)); I_TEST((MD5 Hashing | Multiple Updates));
@ -1088,28 +1089,28 @@ void md5_test_consecutive_updates()
} }
} }
int hmac_md5_tests() static int hmac_md5_tests()
{ {
hmac_md5_test_name(); hmac_md5_test_name();
hmac_md5_test_process(); hmac_md5_test_process();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
int hmac_sha256_tests() static int hmac_sha256_tests()
{ {
hmac_sha256_test_name(); hmac_sha256_test_name();
hmac_sha256_test_process(); hmac_sha256_test_process();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
int hmac_sha512_tests() static int hmac_sha512_tests()
{ {
hmac_sha512_test_name(); hmac_sha512_test_name();
hmac_sha512_test_process(); hmac_sha512_test_process();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void hmac_md5_test_name() static void hmac_md5_test_name()
{ {
I_TEST((HMAC - MD5 | Class name)); I_TEST((HMAC - MD5 | Class name));
Crypto::Authentication::HMAC<Crypto::Hash::MD5> hmac("Well Hello Friends"); Crypto::Authentication::HMAC<Crypto::Hash::MD5> hmac("Well Hello Friends");
@ -1119,7 +1120,7 @@ void hmac_md5_test_name()
PASS; PASS;
} }
void hmac_md5_test_process() static void hmac_md5_test_process()
{ {
{ {
I_TEST((HMAC - MD5 | Basic)); I_TEST((HMAC - MD5 | Basic));
@ -1148,14 +1149,14 @@ void hmac_md5_test_process()
} }
} }
int sha1_tests() static int sha1_tests()
{ {
sha1_test_name(); sha1_test_name();
sha1_test_hash(); sha1_test_hash();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void sha1_test_name() static void sha1_test_name()
{ {
I_TEST((SHA1 class name)); I_TEST((SHA1 class name));
Crypto::Hash::SHA1 sha; Crypto::Hash::SHA1 sha;
@ -1166,7 +1167,7 @@ void sha1_test_name()
PASS; PASS;
} }
void sha1_test_hash() static void sha1_test_hash()
{ {
{ {
I_TEST((SHA256 Hashing | "")); I_TEST((SHA256 Hashing | ""));
@ -1220,14 +1221,14 @@ void sha1_test_hash()
} }
} }
int sha256_tests() static int sha256_tests()
{ {
sha256_test_name(); sha256_test_name();
sha256_test_hash(); sha256_test_hash();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void sha256_test_name() static void sha256_test_name()
{ {
I_TEST((SHA256 class name)); I_TEST((SHA256 class name));
Crypto::Hash::SHA256 sha; Crypto::Hash::SHA256 sha;
@ -1238,7 +1239,7 @@ void sha256_test_name()
PASS; PASS;
} }
void sha256_test_hash() static void sha256_test_hash()
{ {
{ {
I_TEST((SHA256 Hashing | "Well hello friends")); I_TEST((SHA256 Hashing | "Well hello friends"));
@ -1266,7 +1267,7 @@ void sha256_test_hash()
} }
} }
void hmac_sha256_test_name() static void hmac_sha256_test_name()
{ {
I_TEST((HMAC - SHA256 | Class name)); I_TEST((HMAC - SHA256 | Class name));
Crypto::Authentication::HMAC<Crypto::Hash::SHA256> hmac("Well Hello Friends"); Crypto::Authentication::HMAC<Crypto::Hash::SHA256> hmac("Well Hello Friends");
@ -1276,7 +1277,7 @@ void hmac_sha256_test_name()
PASS; PASS;
} }
void hmac_sha256_test_process() static void hmac_sha256_test_process()
{ {
{ {
I_TEST((HMAC - SHA256 | Basic)); I_TEST((HMAC - SHA256 | Basic));
@ -1331,14 +1332,14 @@ void hmac_sha256_test_process()
} }
} }
int sha512_tests() static int sha512_tests()
{ {
sha512_test_name(); sha512_test_name();
sha512_test_hash(); sha512_test_hash();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void sha512_test_name() static void sha512_test_name()
{ {
I_TEST((SHA512 class name)); I_TEST((SHA512 class name));
Crypto::Hash::SHA512 sha; Crypto::Hash::SHA512 sha;
@ -1349,7 +1350,7 @@ void sha512_test_name()
PASS; PASS;
} }
void sha512_test_hash() static void sha512_test_hash()
{ {
{ {
I_TEST((SHA512 Hashing | "Well hello friends")); I_TEST((SHA512 Hashing | "Well hello friends"));
@ -1377,7 +1378,7 @@ void sha512_test_hash()
} }
} }
void hmac_sha512_test_name() static void hmac_sha512_test_name()
{ {
I_TEST((HMAC - SHA512 | Class name)); I_TEST((HMAC - SHA512 | Class name));
Crypto::Authentication::HMAC<Crypto::Hash::SHA512> hmac("Well Hello Friends"); Crypto::Authentication::HMAC<Crypto::Hash::SHA512> hmac("Well Hello Friends");
@ -1387,7 +1388,7 @@ void hmac_sha512_test_name()
PASS; PASS;
} }
void hmac_sha512_test_process() static void hmac_sha512_test_process()
{ {
{ {
I_TEST((HMAC - SHA512 | Basic)); I_TEST((HMAC - SHA512 | Basic));
@ -1416,7 +1417,7 @@ void hmac_sha512_test_process()
} }
} }
int rsa_tests() static int rsa_tests()
{ {
rsa_test_encrypt(); rsa_test_encrypt();
rsa_test_der_parse(); rsa_test_der_parse();
@ -1426,7 +1427,7 @@ int rsa_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void rsa_test_encrypt() static void rsa_test_encrypt()
{ {
{ {
I_TEST((RSA RAW | Encryption)); I_TEST((RSA RAW | Encryption));
@ -1468,7 +1469,7 @@ void rsa_test_encrypt()
} }
} }
void bigint_test_number_theory() static void bigint_test_number_theory()
{ {
{ {
I_TEST((Number Theory | Modular Inverse)); I_TEST((Number Theory | Modular Inverse));
@ -1494,7 +1495,7 @@ void bigint_test_number_theory()
} }
} }
void rsa_emsa_pss_test_create() static void rsa_emsa_pss_test_create()
{ {
{ {
// This is a template validity test // This is a template validity test
@ -1505,7 +1506,7 @@ void rsa_emsa_pss_test_create()
} }
} }
void rsa_test_der_parse() static void rsa_test_der_parse()
{ {
I_TEST((RSA | ASN1 DER / PEM encoded Key import)); I_TEST((RSA | ASN1 DER / PEM encoded Key import));
auto privkey = R"(-----BEGIN RSA PRIVATE KEY----- auto privkey = R"(-----BEGIN RSA PRIVATE KEY-----
@ -1528,7 +1529,7 @@ nrDlBQpuxz7bwSyQO7UCIHrYMnDohgNbwtA5ZpW3H1cKKQQvueWm6sxW9P5sUrZ3
} }
} }
void rsa_test_encrypt_decrypt() static void rsa_test_encrypt_decrypt()
{ {
I_TEST((RSA | Encrypt)); I_TEST((RSA | Encrypt));
dbg() << " creating rsa object"; dbg() << " creating rsa object";
@ -1553,13 +1554,13 @@ void rsa_test_encrypt_decrypt()
} }
} }
int tls_tests() static int tls_tests()
{ {
tls_test_client_hello(); tls_test_client_hello();
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
void tls_test_client_hello() static void tls_test_client_hello()
{ {
I_TEST((TLS | Connect and Data Transfer)); I_TEST((TLS | Connect and Data Transfer));
Core::EventLoop loop; Core::EventLoop loop;
@ -1608,7 +1609,7 @@ void tls_test_client_hello()
loop.exec(); loop.exec();
} }
int adler32_tests() static int adler32_tests()
{ {
auto do_test = [](ReadonlyBytes input, u32 expected_result) { auto do_test = [](ReadonlyBytes input, u32 expected_result) {
I_TEST((CRC32)); I_TEST((CRC32));
@ -1631,7 +1632,7 @@ int adler32_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
int crc32_tests() static int crc32_tests()
{ {
auto do_test = [](ReadonlyBytes input, u32 expected_result) { auto do_test = [](ReadonlyBytes input, u32 expected_result) {
I_TEST((Adler32)); I_TEST((Adler32));
@ -1652,7 +1653,7 @@ int crc32_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
int bigint_tests() static int bigint_tests()
{ {
bigint_test_fibo500(); bigint_test_fibo500();
bigint_addition_edgecases(); bigint_addition_edgecases();
@ -1675,7 +1676,7 @@ int bigint_tests()
return g_some_test_failed ? 1 : 0; return g_some_test_failed ? 1 : 0;
} }
Crypto::UnsignedBigInteger bigint_fibonacci(size_t n) static Crypto::UnsignedBigInteger bigint_fibonacci(size_t n)
{ {
Crypto::UnsignedBigInteger num1(0); Crypto::UnsignedBigInteger num1(0);
Crypto::UnsignedBigInteger num2(1); Crypto::UnsignedBigInteger num2(1);
@ -1687,7 +1688,7 @@ Crypto::UnsignedBigInteger bigint_fibonacci(size_t n)
return num1; return num1;
} }
Crypto::SignedBigInteger bigint_signed_fibonacci(size_t n) static Crypto::SignedBigInteger bigint_signed_fibonacci(size_t n)
{ {
Crypto::SignedBigInteger num1(0); Crypto::SignedBigInteger num1(0);
Crypto::SignedBigInteger num2(1); Crypto::SignedBigInteger num2(1);
@ -1698,7 +1699,7 @@ Crypto::SignedBigInteger bigint_signed_fibonacci(size_t n)
} }
return num1; return num1;
} }
void bigint_test_fibo500() static void bigint_test_fibo500()
{ {
{ {
I_TEST((BigInteger | Fibonacci500)); I_TEST((BigInteger | Fibonacci500));
@ -1712,7 +1713,7 @@ void bigint_test_fibo500()
} }
} }
void bigint_addition_edgecases() static void bigint_addition_edgecases()
{ {
{ {
I_TEST((BigInteger | Edge Cases)); I_TEST((BigInteger | Edge Cases));
@ -1740,7 +1741,7 @@ void bigint_addition_edgecases()
} }
} }
void bigint_subtraction() static void bigint_subtraction()
{ {
{ {
I_TEST((BigInteger | Simple Subtraction 1)); I_TEST((BigInteger | Simple Subtraction 1));
@ -1807,7 +1808,7 @@ void bigint_subtraction()
} }
} }
void bigint_multiplication() static void bigint_multiplication()
{ {
{ {
I_TEST((BigInteger | Simple Multiplication)); I_TEST((BigInteger | Simple Multiplication));
@ -1843,7 +1844,7 @@ void bigint_multiplication()
} }
} }
} }
void bigint_division() static void bigint_division()
{ {
{ {
I_TEST((BigInteger | Simple Division)); I_TEST((BigInteger | Simple Division));
@ -1885,7 +1886,7 @@ void bigint_division()
} }
} }
void bigint_base10() static void bigint_base10()
{ {
{ {
I_TEST((BigInteger | From String)); I_TEST((BigInteger | From String));
@ -1907,7 +1908,7 @@ void bigint_base10()
} }
} }
void bigint_import_export() static void bigint_import_export()
{ {
{ {
I_TEST((BigInteger | BigEndian Decode / Encode roundtrip)); I_TEST((BigInteger | BigEndian Decode / Encode roundtrip));
@ -1955,7 +1956,7 @@ void bigint_import_export()
} }
} }
void bigint_bitwise() static void bigint_bitwise()
{ {
{ {
I_TEST((BigInteger | Basic bitwise or)); I_TEST((BigInteger | Basic bitwise or));
@ -2021,7 +2022,7 @@ void bigint_bitwise()
} }
} }
void bigint_test_signed_fibo500() static void bigint_test_signed_fibo500()
{ {
{ {
I_TEST((Signed BigInteger | Fibonacci500)); I_TEST((Signed BigInteger | Fibonacci500));
@ -2035,7 +2036,7 @@ void bigint_test_signed_fibo500()
} }
} }
void bigint_signed_addition_edgecases() static void bigint_signed_addition_edgecases()
{ {
{ {
I_TEST((Signed BigInteger | Borrow with zero)); I_TEST((Signed BigInteger | Borrow with zero));
@ -2060,7 +2061,7 @@ void bigint_signed_addition_edgecases()
} }
} }
void bigint_signed_subtraction() static void bigint_signed_subtraction()
{ {
{ {
I_TEST((Signed BigInteger | Simple Subtraction 1)); I_TEST((Signed BigInteger | Simple Subtraction 1));
@ -2120,7 +2121,7 @@ void bigint_signed_subtraction()
} }
} }
void bigint_signed_multiplication() static void bigint_signed_multiplication()
{ {
{ {
I_TEST((Signed BigInteger | Simple Multiplication)); I_TEST((Signed BigInteger | Simple Multiplication));
@ -2157,7 +2158,7 @@ void bigint_signed_multiplication()
} }
} }
} }
void bigint_signed_division() static void bigint_signed_division()
{ {
{ {
I_TEST((Signed BigInteger | Simple Division)); I_TEST((Signed BigInteger | Simple Division));
@ -2201,7 +2202,7 @@ void bigint_signed_division()
} }
} }
void bigint_signed_base10() static void bigint_signed_base10()
{ {
{ {
I_TEST((Signed BigInteger | From String)); I_TEST((Signed BigInteger | From String));
@ -2223,7 +2224,7 @@ void bigint_signed_base10()
} }
} }
void bigint_signed_import_export() static void bigint_signed_import_export()
{ {
{ {
I_TEST((Signed BigInteger | BigEndian Decode / Encode roundtrip)); I_TEST((Signed BigInteger | BigEndian Decode / Encode roundtrip));
@ -2251,7 +2252,7 @@ void bigint_signed_import_export()
} }
} }
void bigint_signed_bitwise() static void bigint_signed_bitwise()
{ {
{ {
I_TEST((Signed BigInteger | Bitwise or handles sign)); I_TEST((Signed BigInteger | Bitwise or handles sign));

View file

@ -144,7 +144,7 @@ JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::is_strict_mode)
return JS::Value(interpreter.in_strict_mode()); return JS::Value(interpreter.in_strict_mode());
} }
double get_time_in_ms() static double get_time_in_ms()
{ {
struct timeval tv1; struct timeval tv1;
struct timezone tz1; struct timezone tz1;
@ -154,7 +154,7 @@ double get_time_in_ms()
} }
template<typename Callback> template<typename Callback>
void iterate_directory_recursively(const String& directory_path, Callback callback) static void iterate_directory_recursively(const String& directory_path, Callback callback)
{ {
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots); Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
@ -168,7 +168,7 @@ void iterate_directory_recursively(const String& directory_path, Callback callba
} }
} }
Vector<String> get_test_paths(const String& test_root) static Vector<String> get_test_paths(const String& test_root)
{ {
Vector<String> paths; Vector<String> paths;
@ -201,7 +201,7 @@ void TestRunner::run()
print_test_results(); print_test_results();
} }
Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path) static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path)
{ {
auto file = Core::File::construct(file_path); auto file = Core::File::construct(file_path);
auto result = file->open(Core::IODevice::ReadOnly); auto result = file->open(Core::IODevice::ReadOnly);
@ -225,7 +225,7 @@ Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_pa
return Result<NonnullRefPtr<JS::Program>, ParserError>(program); return Result<NonnullRefPtr<JS::Program>, ParserError>(program);
} }
Optional<JsonValue> get_test_results(JS::Interpreter& interpreter) static Optional<JsonValue> get_test_results(JS::Interpreter& interpreter)
{ {
auto result = interpreter.get_variable("__TestResults__", interpreter.global_object()); auto result = interpreter.get_variable("__TestResults__", interpreter.global_object());
auto json_string = JS::JSONObject::stringify_impl(interpreter, interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined()); auto json_string = JS::JSONObject::stringify_impl(interpreter, interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined());
@ -337,7 +337,7 @@ enum Modifier {
CLEAR, CLEAR,
}; };
void print_modifiers(Vector<Modifier> modifiers) static void print_modifiers(Vector<Modifier> modifiers)
{ {
for (auto& modifier : modifiers) { for (auto& modifier : modifiers) {
auto code = [&]() -> String { auto code = [&]() -> String {

View file

@ -24,11 +24,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/URL.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/JsonValue.h>
#include <AK/JsonObject.h> #include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/URL.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h> #include <LibCore/DirIterator.h>
#include <LibCore/File.h> #include <LibCore/File.h>
@ -42,9 +42,9 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/JSONObject.h> #include <LibJS/Runtime/JSONObject.h>
#include <LibJS/Runtime/MarkedValueList.h> #include <LibJS/Runtime/MarkedValueList.h>
#include <LibWeb/PageView.h>
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h> #include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/PageView.h>
#include <sys/time.h> #include <sys/time.h>
#define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__" #define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
@ -164,12 +164,12 @@ private:
RefPtr<JS::Program> m_web_test_common; RefPtr<JS::Program> m_web_test_common;
}; };
double get_time_in_ms() static double get_time_in_ms()
{ {
struct timeval tv1; struct timeval tv1;
struct timezone tz1; struct timezone tz1;
auto return_code = gettimeofday(&tv1, &tz1); auto return_code = gettimeofday(&tv1, &tz1);
ASSERT(return_code >= 0); ASSERT(return_code >= 0);
return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0; return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0;
} }
@ -188,7 +188,7 @@ void iterate_directory_recursively(const String& directory_path, Callback callba
} }
} }
Vector<String> get_test_paths(const String& test_root) static Vector<String> get_test_paths(const String& test_root)
{ {
Vector<String> paths; Vector<String> paths;
@ -202,7 +202,8 @@ Vector<String> get_test_paths(const String& test_root)
return paths; return paths;
} }
void TestRunner::run() { void TestRunner::run()
{
size_t progress_counter = 0; size_t progress_counter = 0;
auto test_paths = get_test_paths(m_web_test_root); auto test_paths = get_test_paths(m_web_test_root);
@ -228,8 +229,7 @@ void TestRunner::run() {
[page_to_load](auto error) { [page_to_load](auto error) {
printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters()); printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters());
exit(1); exit(1);
} });
);
}; };
for (auto& path : test_paths) { for (auto& path : test_paths) {
@ -247,7 +247,7 @@ void TestRunner::run() {
print_test_results(); print_test_results();
} }
Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path) static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path)
{ {
auto file = Core::File::construct(file_path); auto file = Core::File::construct(file_path);
auto result = file->open(Core::IODevice::ReadOnly); auto result = file->open(Core::IODevice::ReadOnly);
@ -271,7 +271,7 @@ Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_pa
return Result<NonnullRefPtr<JS::Program>, ParserError>(program); return Result<NonnullRefPtr<JS::Program>, ParserError>(program);
} }
Optional<JsonValue> get_test_results(JS::Interpreter& interpreter) static Optional<JsonValue> get_test_results(JS::Interpreter& interpreter)
{ {
auto result = interpreter.get_variable("__TestResults__", interpreter.global_object()); auto result = interpreter.get_variable("__TestResults__", interpreter.global_object());
auto json_string = JS::JSONObject::stringify_impl(interpreter, interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined()); auto json_string = JS::JSONObject::stringify_impl(interpreter, interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined());
@ -333,8 +333,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
new_interpreter.global_object().define_property( new_interpreter.global_object().define_property(
"libweb_tester", "libweb_tester",
new_interpreter.heap().allocate<TestRunnerObject>(new_interpreter.global_object(), new_interpreter.global_object()), new_interpreter.heap().allocate<TestRunnerObject>(new_interpreter.global_object(), new_interpreter.global_object()),
JS::Attribute::Enumerable | JS::Attribute::Configurable JS::Attribute::Enumerable | JS::Attribute::Configurable);
);
new_interpreter.run(new_interpreter.global_object(), *m_js_test_common); new_interpreter.run(new_interpreter.global_object(), *m_js_test_common);
new_interpreter.run(new_interpreter.global_object(), *m_web_test_common); new_interpreter.run(new_interpreter.global_object(), *m_web_test_common);
new_interpreter.run(new_interpreter.global_object(), *file_program.value()); new_interpreter.run(new_interpreter.global_object(), *file_program.value());
@ -416,8 +415,7 @@ JSFileResult TestRunner::run_file_test(const String& test_path)
[page_to_load](auto error) { [page_to_load](auto error) {
printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters()); printf("Failed to load test page: %s (%s)", page_to_load.to_string().characters(), error.characters());
exit(1); exit(1);
} });
);
return file_result; return file_result;
} }
@ -435,7 +433,7 @@ enum Modifier {
CLEAR, CLEAR,
}; };
void print_modifiers(Vector<Modifier> modifiers) static void print_modifiers(Vector<Modifier> modifiers)
{ {
for (auto& modifier : modifiers) { for (auto& modifier : modifiers) {
auto code = [&]() -> String { auto code = [&]() -> String {

View file

@ -35,7 +35,7 @@
bool g_there_was_an_error = false; bool g_there_was_an_error = false;
[[noreturn]] void fatal_error(const char* format, ...) [[noreturn]] static void fatal_error(const char* format, ...)
{ {
fputs("\033[31m", stderr); fputs("\033[31m", stderr);
@ -334,14 +334,14 @@ private:
Mode m_mode { Same }; Mode m_mode { Same };
}; };
OwnPtr<Condition> parse_complex_expression(char* argv[]); static OwnPtr<Condition> parse_complex_expression(char* argv[]);
static bool should_treat_expression_as_single_string(const StringView& arg_after) static bool should_treat_expression_as_single_string(const StringView& arg_after)
{ {
return arg_after.is_null() || arg_after == "-a" || arg_after == "-o"; return arg_after.is_null() || arg_after == "-a" || arg_after == "-o";
} }
OwnPtr<Condition> parse_simple_expression(char* argv[]) static OwnPtr<Condition> parse_simple_expression(char* argv[])
{ {
StringView arg = argv[optind]; StringView arg = argv[optind];
if (arg.is_null()) { if (arg.is_null()) {
@ -468,7 +468,7 @@ OwnPtr<Condition> parse_simple_expression(char* argv[])
} }
} }
OwnPtr<Condition> parse_complex_expression(char* argv[]) static OwnPtr<Condition> parse_complex_expression(char* argv[])
{ {
auto command = parse_simple_expression(argv); auto command = parse_simple_expression(argv);

View file

@ -52,7 +52,7 @@
} \ } \
} while (0) } while (0)
void test_read_from_directory() static void test_read_from_directory()
{ {
char buffer[BUFSIZ]; char buffer[BUFSIZ];
int fd = open("/", O_DIRECTORY | O_RDONLY); int fd = open("/", O_DIRECTORY | O_RDONLY);
@ -63,7 +63,7 @@ void test_read_from_directory()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_write_to_directory() static void test_write_to_directory()
{ {
char str[] = "oh frick"; char str[] = "oh frick";
int fd = open("/", O_DIRECTORY | O_RDONLY); int fd = open("/", O_DIRECTORY | O_RDONLY);
@ -76,7 +76,7 @@ void test_write_to_directory()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_read_from_writeonly() static void test_read_from_writeonly()
{ {
char buffer[BUFSIZ]; char buffer[BUFSIZ];
int fd = open("/tmp/xxxx123", O_CREAT | O_WRONLY); int fd = open("/tmp/xxxx123", O_CREAT | O_WRONLY);
@ -87,7 +87,7 @@ void test_read_from_writeonly()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_write_to_readonly() static void test_write_to_readonly()
{ {
char str[] = "hello"; char str[] = "hello";
int fd = open("/tmp/abcd123", O_CREAT | O_RDONLY); int fd = open("/tmp/abcd123", O_CREAT | O_RDONLY);
@ -98,7 +98,7 @@ void test_write_to_readonly()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_read_past_eof() static void test_read_past_eof()
{ {
char buffer[BUFSIZ]; char buffer[BUFSIZ];
int fd = open("/home/anon/myfile.txt", O_RDONLY); int fd = open("/home/anon/myfile.txt", O_RDONLY);
@ -118,7 +118,7 @@ void test_read_past_eof()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_ftruncate_readonly() static void test_ftruncate_readonly()
{ {
int fd = open("/tmp/trunctest", O_RDONLY | O_CREAT, 0666); int fd = open("/tmp/trunctest", O_RDONLY | O_CREAT, 0666);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -127,7 +127,7 @@ void test_ftruncate_readonly()
close(fd); close(fd);
} }
void test_ftruncate_negative() static void test_ftruncate_negative()
{ {
int fd = open("/tmp/trunctest", O_RDWR | O_CREAT, 0666); int fd = open("/tmp/trunctest", O_RDWR | O_CREAT, 0666);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -136,7 +136,7 @@ void test_ftruncate_negative()
close(fd); close(fd);
} }
void test_mmap_directory() static void test_mmap_directory()
{ {
int fd = open("/tmp", O_RDONLY | O_DIRECTORY); int fd = open("/tmp", O_RDONLY | O_DIRECTORY);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -152,7 +152,7 @@ void test_mmap_directory()
close(fd); close(fd);
} }
void test_tmpfs_read_past_end() static void test_tmpfs_read_past_end()
{ {
int fd = open("/tmp/x", O_RDWR | O_CREAT | O_TRUNC, 0600); int fd = open("/tmp/x", O_RDWR | O_CREAT | O_TRUNC, 0600);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -171,7 +171,7 @@ void test_tmpfs_read_past_end()
close(fd); close(fd);
} }
void test_procfs_read_past_end() static void test_procfs_read_past_end()
{ {
int fd = open("/proc/uptime", O_RDONLY); int fd = open("/proc/uptime", O_RDONLY);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -187,7 +187,7 @@ void test_procfs_read_past_end()
close(fd); close(fd);
} }
void test_open_create_device() static void test_open_create_device()
{ {
int fd = open("/tmp/fakedevice", (O_RDWR | O_CREAT), (S_IFCHR | 0600)); int fd = open("/tmp/fakedevice", (O_RDWR | O_CREAT), (S_IFCHR | 0600));
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -205,7 +205,7 @@ void test_open_create_device()
close(fd); close(fd);
} }
void test_unlink_symlink() static void test_unlink_symlink()
{ {
int rc = symlink("/proc/2/foo", "/tmp/linky"); int rc = symlink("/proc/2/foo", "/tmp/linky");
if (rc < 0) { if (rc < 0) {
@ -223,7 +223,7 @@ void test_unlink_symlink()
} }
} }
void test_eoverflow() static void test_eoverflow()
{ {
int fd = open("/tmp/x", O_RDWR); int fd = open("/tmp/x", O_RDWR);
ASSERT(fd >= 0); ASSERT(fd >= 0);
@ -243,7 +243,7 @@ void test_eoverflow()
close(fd); close(fd);
} }
void test_rmdir_while_inside_dir() static void test_rmdir_while_inside_dir()
{ {
int rc = mkdir("/home/anon/testdir", 0700); int rc = mkdir("/home/anon/testdir", 0700);
ASSERT(rc == 0); ASSERT(rc == 0);
@ -263,7 +263,7 @@ void test_rmdir_while_inside_dir()
ASSERT(rc == 0); ASSERT(rc == 0);
} }
void test_writev() static void test_writev()
{ {
int pipefds[2]; int pipefds[2];
pipe(pipefds); pipe(pipefds);
@ -294,7 +294,7 @@ void test_writev()
close(pipefds[1]); close(pipefds[1]);
} }
void test_rmdir_root() static void test_rmdir_root()
{ {
int rc = rmdir("/"); int rc = rmdir("/");
if (rc != -1 || errno != EBUSY) { if (rc != -1 || errno != EBUSY) {
@ -303,7 +303,7 @@ void test_rmdir_root()
} }
} }
int main(int, char**) int main()
{ {
int rc; int rc;
EXPECT_ERROR_2(ENOTDIR, open, "/dev/zero", (O_DIRECTORY | O_RDONLY)); EXPECT_ERROR_2(ENOTDIR, open, "/dev/zero", (O_DIRECTORY | O_RDONLY));