Debian Codegraph @

storage/maria/libmarias3/tests/large_file.c

raw
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * Copyright 2019 MariaDB Corporation Ab. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20 #include <yatl/lite.h>
21 #include <libmarias3/marias3.h>
22
23 /* Tests basic PUT/GET a 64MB file */
24
25 int main(int argc, char *argv[])
26 {
27 int res;
28 uint8_t *data;
29 size_t length;
30 size_t new_buffer_size;
31 ms3_st *ms3;
32 char *test_string = malloc(64 * 1024 * 1024);
33 char *s3key = getenv("S3KEY");
34 char *s3secret = getenv("S3SECRET");
35 char *s3region = getenv("S3REGION");
36 char *s3bucket = getenv("S3BUCKET");
37 char *s3host = getenv("S3HOST");
38 char *s3noverify = getenv("S3NOVERIFY");
39 char *s3usehttp = getenv("S3USEHTTP");
40 char *s3port = getenv("S3PORT");
41 memset(test_string, 'a', 64 * 1024 * 1024);
42
43 (void) argc;
44 (void) argv;
45
46 SKIP_IF_(!s3key, "Environemnt variable S3KEY missing");
47 SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing");
48 SKIP_IF_(!s3region, "Environemnt variable S3REGION missing");
49 SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing");
50
51 ms3_library_init();
52 ms3 = ms3_init(s3key, s3secret, s3region, s3host);
53
54 if (s3noverify && !strcmp(s3noverify, "1"))
55 {
56 ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL);
57 }
58
59 if (s3usehttp && !strcmp(s3usehttp, "1"))
60 {
61 ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL);
62 }
63
64 if (s3port)
65 {
66 int port = atoi(s3port);
67 ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port);
68 }
69
70 // ms3_debug(true);
71 ASSERT_NOT_NULL(ms3);
72
73 res = ms3_put(ms3, s3bucket, "test/large_file.dat",
74 (const uint8_t *)test_string,
75 64 * 1024 * 1024);
76 ASSERT_EQ_(res, 0, "Result: %u", res);
77 new_buffer_size = 4 * 1024 * 1024;
78 res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size);
79 ASSERT_EQ_(res, 0, "Result: %u", res);
80 res = ms3_get(ms3, s3bucket, "test/large_file.dat", &data, &length);
81 ASSERT_EQ_(res, 0, "Result: %u", res);
82 ASSERT_EQ(length, 64 * 1024 * 1024);
83 res = ms3_delete(ms3, s3bucket, "test/large_file.dat");
84 ASSERT_EQ_(res, 0, "Result: %u", res);
85 free(test_string);
86 ms3_free(data);
87 ms3_deinit(ms3);
88 ms3_library_deinit();
89 return 0;
90 }