Invoke tear_down when exiting test_encode_tls_sct() prematurely
[openssl.git] / test / moduleloadtest.c
1 /*
2  * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * Extremely simple dynamic loader, must never be linked with anything other
12  * than the standard C library.  Its purpose is to try to load a dynamic module
13  * and verify the presence of one symbol, if that's given.
14  */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <openssl/core.h>
19 #include "simpledynamic.h"
20
21 static int test_load(const char *path, const char *symbol)
22 {
23 #ifdef SD_INIT
24     SD sd = SD_INIT;
25     SD_SYM sym;
26
27     return sd_load(path, &sd, SD_MODULE)
28         && (symbol == NULL || sd_sym(sd, symbol, &sym))
29         && sd_close(sd);
30 #else
31     fprintf(stderr, "No dynamic loader\n");
32     return 0;
33 #endif
34 }
35
36 int main(int argc, char *argv[])
37 {
38     const char *m, *s;
39
40     if (argc != 2 && argc != 3) {
41         fprintf(stderr, "Usage: %s sharedobject [ entrypoint ]\n", argv[0]);
42         return 1;
43     }
44
45     m = argv[1];
46     s = argc == 3 ? argv[2] : NULL;
47
48     return test_load(m, s) ? 0 : 1;
49 }