diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:07:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:07:14 +0000 |
commit | a175314c3e5827eb193872241446f2f8f5c9d33c (patch) | |
tree | cd3d60ca99ae00829c52a6ca79150a5b6e62528b /storage/maria/libmarias3/tests | |
parent | Initial commit. (diff) | |
download | mariadb-10.5-a175314c3e5827eb193872241446f2f8f5c9d33c.tar.xz mariadb-10.5-a175314c3e5827eb193872241446f2f8f5c9d33c.zip |
Adding upstream version 1:10.5.12.upstream/1%10.5.12upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/maria/libmarias3/tests')
-rw-r--r-- | storage/maria/libmarias3/tests/basic.c | 180 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/basic_host.c | 158 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/copy.c | 181 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/custom_malloc.c | 207 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/error.c | 58 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/include.am | 69 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/large_file.c | 90 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/list.c | 156 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/longlist.c | 283 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/prefix.c | 129 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/small_buffer.c | 98 | ||||
-rw-r--r-- | storage/maria/libmarias3/tests/snowman.c | 180 |
12 files changed, 1789 insertions, 0 deletions
diff --git a/storage/maria/libmarias3/tests/basic.c b/storage/maria/libmarias3/tests/basic.c new file mode 100644 index 00000000..309c77bb --- /dev/null +++ b/storage/maria/libmarias3/tests/basic.c @@ -0,0 +1,180 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic put, list, get, status, delete using the thread calls */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + uint8_t *data; + size_t length; + int i; + bool found; + uint8_t list_version; + const char *test_string = "Another one bites the dust"; + ms3_status_st status; + ms3_st *ms3; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/basic_thread.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + // A prefix that will give no results; + res = ms3_list(ms3, s3bucket, "asdfghjkl", &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_NULL_(list, "List not empty"); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/basic_thread.txt", 21)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + // Retry list with V1 API + list_version = 1; + list = NULL; + ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version); + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/basic_thread.txt", 21)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_get(ms3, s3bucket, "test/basic_thread.txt", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 26); + ASSERT_STREQ((char *)data, test_string); + + for (i = 0; i <= 3; i++) + { + res = ms3_status(ms3, s3bucket, "test/basic_thread.txt", &status); + + if (res == MS3_ERR_NOT_FOUND) + { + continue; + } + + ASSERT_EQ_(res, 0, "Result: %u", res); + + if (res == 0) + { + break; + } + } + + ASSERT_EQ(status.length, 26); + ASSERT_NEQ(status.created, 0); + res = ms3_delete(ms3, s3bucket, "test/basic_thread.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + ms3_free(data); + res = ms3_get(ms3, s3bucket, "test/basic_thread.txt", &data, &length); + ASSERT_NEQ_(res, 0, "Object should error"); + ASSERT_NULL_(data, "Data should be NULL"); + ASSERT_EQ_(length, 0, "There should be no data"); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/basic_host.c b/storage/maria/libmarias3/tests/basic_host.c new file mode 100644 index 00000000..7b9aa3da --- /dev/null +++ b/storage/maria/libmarias3/tests/basic_host.c @@ -0,0 +1,158 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic calls with an expicit hostname */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + uint8_t *data; + size_t length; + int i; + bool found; + uint8_t protocol_version; + const char *test_string = "Another one bites the dust"; + ms3_status_st status; + ms3_st *ms3; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + SKIP_IF_(s3host, "Test is for non-explicit hostnames"); + + (void) argc; + (void) argv; + + if (!s3host || s3host[0] == '\0') + { + const char *default_host = "s3.amazonaws.com"; + s3host = (char *)default_host; + } + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + protocol_version = 2; + ms3_set_option(ms3, MS3_OPT_FORCE_PROTOCOL_VERSION, &protocol_version); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/basic_host.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + // A prefix that will give no results; + res = ms3_list(ms3, s3bucket, "asdfghjkl", &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_NULL_(list, "List not empty"); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/basic_host.txt", 19)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_get(ms3, s3bucket, "test/basic_host.txt", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 26); + ASSERT_STREQ((char *)data, test_string); + + for (i = 0; i <= 3; i++) + { + res = ms3_status(ms3, s3bucket, "test/basic_host.txt", &status); + + if (res == MS3_ERR_NOT_FOUND) + { + continue; + } + + ASSERT_EQ_(res, 0, "Result: %u", res); + + if (res == 0) + { + break; + } + } + + ASSERT_EQ(status.length, 26); + ASSERT_NEQ(status.created, 0); + res = ms3_delete(ms3, s3bucket, "test/basic_host.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + ms3_free(data); + res = ms3_get(ms3, s3bucket, "test/basic_host.txt", &data, &length); + ASSERT_NEQ_(res, 0, "Object should error"); + ASSERT_NULL_(data, "Data should be NULL"); + ASSERT_EQ_(length, 0, "There should be no data"); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/copy.c b/storage/maria/libmarias3/tests/copy.c new file mode 100644 index 00000000..9587e214 --- /dev/null +++ b/storage/maria/libmarias3/tests/copy.c @@ -0,0 +1,181 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests copy and move calls */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + uint8_t *data; + size_t length; + bool found, found_orig, found_new; + ms3_st *ms3; + const char *test_string = "Another one bites the dust"; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/copy_test.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_copy(ms3, s3bucket, "test/copy_test.txt", s3bucket, + "test/copied.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/copied.txt", 12)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Copied file not found"); + + // Test with hash chars in filename + + res = ms3_put(ms3, s3bucket, "test/copy_###_test.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_copy(ms3, s3bucket, "test/copy_###_test.txt", s3bucket, + "test/copied###.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/copied###.txt", 12)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Copied file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Copied file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Copied file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_move(ms3, s3bucket, "test/copy_test.txt", s3bucket, "test/moved.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found_orig = false; + found_new = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/moved.txt", 12)) + { + found_new = true; + } + else if (!strncmp(list_it->key, "test/copy_test.txt", 12)) + { + found_orig = true; + } + + + list_it = list_it->next; + } + + ASSERT_EQ_(found_new, 1, "Copied file not found"); + ASSERT_EQ_(found_orig, 0, "Original file still exists after move"); + + res = ms3_get(ms3, s3bucket, "test/moved.txt", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 26); + ASSERT_STREQ((char *)data, test_string); + + res = ms3_delete(ms3, s3bucket, "test/moved.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + res = ms3_delete(ms3, s3bucket, "test/copied.txt"); + res = ms3_delete(ms3, s3bucket, "test/copy_###_test.txt"); + res = ms3_delete(ms3, s3bucket, "test/copied###.txt"); + + ms3_free(data); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/custom_malloc.c b/storage/maria/libmarias3/tests/custom_malloc.c new file mode 100644 index 00000000..80f1b393 --- /dev/null +++ b/storage/maria/libmarias3/tests/custom_malloc.c @@ -0,0 +1,207 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests functions using custom allocators */ + +static void *cust_malloc(size_t size) +{ + printf("Malloc of %zu bytes\n", size); + return malloc(size); +} + +static void cust_free(void *ptr) +{ + printf("Free called\n"); + free(ptr); +} + +static void *cust_realloc(void *ptr, size_t size) +{ + printf("Realloc of %zu bytes\n", size); + return realloc(ptr, size); +} + +static char *cust_strdup(const char *str) +{ + printf("Strdup called\n"); + return strdup(str); +} + +static void *cust_calloc(size_t nmemb, size_t size) +{ + printf("Calloc of %zu elements, %zu size\n", nmemb, size); + return calloc(nmemb, size); +} + +int main(int argc, char *argv[]) +{ + int res; + int i; + ms3_list_st *list = NULL, *list_it = NULL; + uint8_t *data; + size_t length; + bool found; + uint8_t list_version; + const char *test_string = "Another one bites the dust"; + ms3_status_st status; + ms3_st *ms3; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init_malloc(cust_malloc, cust_free, cust_realloc, cust_strdup, + cust_calloc); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(true); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/custom_malloc.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + // A prefix that will give no results; + res = ms3_list(ms3, s3bucket, "asdfghjkl", &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_NULL_(list, "List not empty"); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/custom_malloc.txt", 12)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + // Retry list with V1 API + list_version = 1; + list = NULL; + ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version); + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "test/custom_malloc.txt", 12)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 26, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_get(ms3, s3bucket, "test/custom_malloc.txt", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 26); + ASSERT_STREQ((char *)data, test_string); + + for (i = 0; i <= 3; i++) + { + res = ms3_status(ms3, s3bucket, "test/custom_malloc.txt", &status); + + if (res == MS3_ERR_NOT_FOUND) + { + continue; + } + + ASSERT_EQ_(res, 0, "Result: %u", res); + + if (res == 0) + { + break; + } + } + + ASSERT_EQ(status.length, 26); + ASSERT_NEQ(status.created, 0); + res = ms3_delete(ms3, s3bucket, "test/custom_malloc.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + ms3_free(data); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/error.c b/storage/maria/libmarias3/tests/error.c new file mode 100644 index 00000000..9be45d44 --- /dev/null +++ b/storage/maria/libmarias3/tests/error.c @@ -0,0 +1,58 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic error handling */ + +int main(int argc, char *argv[]) +{ + uint8_t *data; + size_t length; + const char *errmsg; + uint8_t res; + ms3_st *ms3 = ms3_init("12345678901234567890", + "1234567890123456789012345678901234567890", "us-east-1", NULL); + + (void) argc; + (void) argv; + + // Enable here so cppcheck shows coverage + ms3_debug(); + ASSERT_NOT_NULL(ms3); + errmsg = ms3_error(255); + ASSERT_STREQ(errmsg, "No such error code"); + errmsg = ms3_error(0); + ASSERT_STREQ(errmsg, "No error"); + res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length); + printf("%d\n", res); + printf("%s\n", ms3_server_error(ms3)); + ASSERT_EQ(res, MS3_ERR_AUTH); // Bad auth + free(data); + ms3_deinit(ms3); + ms3 = ms3_init("12345678901234567890", + "1234567890123456789012345678901234567890", "us-east-1", "bad-domain"); + res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length); + ASSERT_EQ(res, MS3_ERR_REQUEST_ERROR); + free(data); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/include.am b/storage/maria/libmarias3/tests/include.am new file mode 100644 index 00000000..1cb25a1c --- /dev/null +++ b/storage/maria/libmarias3/tests/include.am @@ -0,0 +1,69 @@ +# vim:ft=automake +# Copyright (C) 2012 Data Differential +# All rights reserved. +# +# Use and distribution licensed under the BSD license. See +# the COPYING file in the parent directory for full text. +# +# included from Top Level Makefile.am +# All paths should be given relative to the root + +LIBTOOL_COMMAND= ${abs_top_builddir}/libtool --mode=execute +GDB_COMMAND= $(LIBTOOL_COMMAND) gdb -f -x support/run.gdb + +t_error_SOURCES= tests/error.c +t_error_LDADD= src/libmarias3.la +check_PROGRAMS+= t/error +noinst_PROGRAMS+= t/error + +t_basic_SOURCES= tests/basic.c +t_basic_LDADD= src/libmarias3.la +check_PROGRAMS+= t/basic +noinst_PROGRAMS+= t/basic + +t_snowman_SOURCES= tests/snowman.c +t_snowman_LDADD= src/libmarias3.la +check_PROGRAMS+= t/snowman +noinst_PROGRAMS+= t/snowman + +t_basic_host_SOURCES= tests/basic_host.c +t_basic_host_LDADD= src/libmarias3.la +check_PROGRAMS+= t/basic_host +noinst_PROGRAMS+= t/basic_host + +t_copy_SOURCES= tests/copy.c +t_copy_LDADD= src/libmarias3.la +check_PROGRAMS+= t/copy +noinst_PROGRAMS+= t/copy + +t_large_file_SOURCES= tests/large_file.c +t_large_file_LDADD= src/libmarias3.la +check_PROGRAMS+= t/large_file +noinst_PROGRAMS+= t/large_file + +t_small_buffer_SOURCES= tests/small_buffer.c +t_small_buffer_LDADD= src/libmarias3.la +check_PROGRAMS+= t/small_buffer +noinst_PROGRAMS+= t/small_buffer + +t_prefix_SOURCES= tests/prefix.c +t_prefix_LDADD= src/libmarias3.la +check_PROGRAMS+= t/prefix +noinst_PROGRAMS+= t/prefix + +t_longlist_SOURCES= tests/longlist.c +t_longlist_LDADD= src/libmarias3.la +t_longlist_LDADD+= -lpthread +check_PROGRAMS+= t/longlist +noinst_PROGRAMS+= t/longlist + +t_custom_malloc_SOURCES= tests/custom_malloc.c +t_custom_malloc_LDADD= src/libmarias3.la +check_PROGRAMS+= t/custom_malloc +noinst_PROGRAMS+= t/custom_malloc + +t_list_SOURCES= tests/list.c +t_list_LDADD= src/libmarias3.la +check_PROGRAMS+= t/list +noinst_PROGRAMS+= t/list + diff --git a/storage/maria/libmarias3/tests/large_file.c b/storage/maria/libmarias3/tests/large_file.c new file mode 100644 index 00000000..b25213f8 --- /dev/null +++ b/storage/maria/libmarias3/tests/large_file.c @@ -0,0 +1,90 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic PUT/GET a 64MB file */ + +int main(int argc, char *argv[]) +{ + int res; + uint8_t *data; + size_t length; + size_t new_buffer_size; + ms3_st *ms3; + char *test_string = malloc(64 * 1024 * 1024); + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + memset(test_string, 'a', 64 * 1024 * 1024); + + (void) argc; + (void) argv; + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(true); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/large_file.dat", + (const uint8_t *)test_string, + 64 * 1024 * 1024); + ASSERT_EQ_(res, 0, "Result: %u", res); + new_buffer_size = 4 * 1024 * 1024; + res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size); + ASSERT_EQ_(res, 0, "Result: %u", res); + res = ms3_get(ms3, s3bucket, "test/large_file.dat", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 64 * 1024 * 1024); + res = ms3_delete(ms3, s3bucket, "test/large_file.dat"); + ASSERT_EQ_(res, 0, "Result: %u", res); + free(test_string); + ms3_free(data); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/list.c b/storage/maria/libmarias3/tests/list.c new file mode 100644 index 00000000..ef268730 --- /dev/null +++ b/storage/maria/libmarias3/tests/list.c @@ -0,0 +1,156 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests list command */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + ms3_st *ms3; + bool found, found_bad; + uint8_t list_version; + const char *test_string = "Another one bites the dust"; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "list1/test1.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + res = ms3_put(ms3, s3bucket, "list2/test2.txt", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + // A prefix that will give no results; + res = ms3_list_dir(ms3, s3bucket, "asdfghjkl", &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_NULL_(list, "List not empty"); + + res = ms3_list_dir(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + found_bad = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "list1/test1.txt", 15)) + { + found_bad = true; + } + + if (!strncmp(list_it->key, "list2/", 6)) + { + found = true; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + ASSERT_NEQ_(found_bad, 1, "File listed should not be here"); + + if (!list) + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + // Retry list with V1 API + list_version = 1; + list = NULL; + ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version); + res = ms3_list_dir(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "list1/test1.txt", 15)) + { + found_bad = true; + } + + if (!strncmp(list_it->key, "list2/", 6)) + { + found = true; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + ASSERT_NEQ_(found_bad, 1, "File listed should not be here"); + + if (!list) + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_delete(ms3, s3bucket, "list1/test1.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + res = ms3_delete(ms3, s3bucket, "list2/test2.txt"); + ASSERT_EQ_(res, 0, "Result: %u", res); + + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/longlist.c b/storage/maria/libmarias3/tests/longlist.c new file mode 100644 index 00000000..5a14031c --- /dev/null +++ b/storage/maria/libmarias3/tests/longlist.c @@ -0,0 +1,283 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> +#include <pthread.h> + +/* Tests listing 1500 items + * This test creates 1500 items using 10 threads, lists them to check + * we can get them all due to the 1000 item pagination limit and then + * deletes them using 10 threads. + */ + +struct thread_info +{ + pthread_t thread_id; + int thread_num; + int start_count; + char *s3bucket; + char *s3key; + char *s3secret; + char *s3region; + char *s3host; + char *s3port; + bool usehttp; + bool noverify; +}; + +const char *test_string = "Another one bites the dust"; + +static void *put_thread(void *arg) +{ + int i; + struct thread_info *tinfo = arg; + ms3_st *ms3 = ms3_init(tinfo->s3key, tinfo->s3secret, tinfo->s3region, + tinfo->s3host); + + if (tinfo->noverify) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (tinfo->usehttp) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (tinfo->s3port) + { + int port = atol(tinfo->s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + + for (i = tinfo->start_count; i < tinfo->start_count + 150; i++) + { + uint8_t res; + char fname[64]; + snprintf(fname, 64, "listtest/list-%d.dat", i); + res = ms3_put(ms3, tinfo->s3bucket, fname, (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ(res, 0); + } + + ms3_deinit(ms3); + + return NULL; +} + +static void *delete_thread(void *arg) +{ + int i; + struct thread_info *tinfo = arg; + ms3_st *ms3 = ms3_init(tinfo->s3key, tinfo->s3secret, tinfo->s3region, + tinfo->s3host); + + if (tinfo->noverify) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (tinfo->usehttp) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (tinfo->s3port) + { + int port = atol(tinfo->s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + + for (i = tinfo->start_count; i < tinfo->start_count + 150; i++) + { + uint8_t res; + char fname[64]; + snprintf(fname, 64, "listtest/list-%d.dat", i); + res = ms3_delete(ms3, tinfo->s3bucket, fname); + ASSERT_EQ(res, 0); + } + + ms3_deinit(ms3); + return NULL; +} + + +int main(int argc, char *argv[]) +{ + + + int tnum; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + bool noverify = false; + bool usehttp = false; + struct thread_info *tinfo; + int start_count; + uint8_t res; + uint8_t list_version; + pthread_attr_t attr; + ms3_st *ms3; + int res_count; + ms3_list_st *list = NULL, *list_it = NULL; + + if (s3noverify && !strcmp(s3noverify, "1")) + { + noverify = true; + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + usehttp = true; + } + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + (void) argc; + (void) argv; + ms3_library_init(); + +// ms3_debug(true); + + tinfo = calloc(10, sizeof(struct thread_info)); + + start_count = 1000; + + pthread_attr_init(&attr); + + // Write 1500 files using 10 threads + printf("Writing 1500 items\n"); + + for (tnum = 0; tnum < 10; tnum++) + { + tinfo[tnum].thread_num = tnum + 1; + tinfo[tnum].start_count = start_count; + start_count += 150; + tinfo[tnum].s3key = s3key; + tinfo[tnum].s3secret = s3secret; + tinfo[tnum].s3region = s3region; + tinfo[tnum].s3host = s3host; + tinfo[tnum].s3bucket = s3bucket; + tinfo[tnum].s3port = s3port; + tinfo[tnum].noverify = noverify; + tinfo[tnum].usehttp = usehttp; + pthread_create(&tinfo[tnum].thread_id, &attr, + &put_thread, &tinfo[tnum]); + } + + for (tnum = 0; tnum < 10; tnum++) + { + pthread_join(tinfo[tnum].thread_id, NULL); + } + + free(tinfo); + + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (noverify) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (usehttp) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + + res = ms3_list(ms3, s3bucket, "listtest/", &list); + ASSERT_EQ(res, 0); + list_it = list; + res_count = 0; + + while (list_it) + { + res_count++; + list_it = list_it->next; + } + + printf("Found %d items\n", res_count); + ASSERT_EQ(res_count, 1500); + + // Reattempt with list version 1 + list_version = 1; + list = NULL; + ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version); + res = ms3_list(ms3, s3bucket, "listtest/", &list); + ASSERT_EQ(res, 0); + list_it = list; + res_count = 0; + + while (list_it) + { + res_count++; + list_it = list_it->next; + } + + printf("V1 Found %d items\n", res_count); + ASSERT_EQ(res_count, 1500); + + ms3_deinit(ms3); + + tinfo = calloc(10, sizeof(struct thread_info)); + start_count = 1000; + + // Destroy 1500 files using 10 threads + printf("Deleting 1500 items"); + + for (tnum = 0; tnum < 10; tnum++) + { + tinfo[tnum].thread_num = tnum + 1; + tinfo[tnum].start_count = start_count; + start_count += 150; + tinfo[tnum].s3key = s3key; + tinfo[tnum].s3secret = s3secret; + tinfo[tnum].s3region = s3region; + tinfo[tnum].s3host = s3host; + tinfo[tnum].s3bucket = s3bucket; + tinfo[tnum].noverify = noverify; + tinfo[tnum].usehttp = usehttp; + tinfo[tnum].s3port = s3port; + pthread_create(&tinfo[tnum].thread_id, &attr, + &delete_thread, &tinfo[tnum]); + } + + for (tnum = 0; tnum < 10; tnum++) + { + pthread_join(tinfo[tnum].thread_id, NULL); + } + + free(tinfo); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/prefix.c b/storage/maria/libmarias3/tests/prefix.c new file mode 100644 index 00000000..672120dd --- /dev/null +++ b/storage/maria/libmarias3/tests/prefix.c @@ -0,0 +1,129 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +#include <unistd.h> +/* Test adds two files and checks that list prefix filters one out */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + int i; + ms3_st *ms3; + bool found_good, found_bad; + const char *test_string = "Another one bites the dust"; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(true); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/prefix.txt", (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ(res, 0); + res = ms3_put(ms3, s3bucket, "other/prefix.txt", (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ(res, 0); + + found_good = false; + found_bad = false; + + for (i = 0; i <= 3; i++) + { + uint8_t file_count; + res = ms3_list(ms3, s3bucket, "test", &list); + ASSERT_EQ(res, 0); + list_it = list; + file_count = 0; + + while (list_it) + { + if (!strncmp(list_it->key, "test/prefix.txt", 12)) + { + found_good = true; + } + + if (!strncmp(list_it->key, "other/prefix.txt", 12)) + { + found_bad = true; + } + + list_it = list_it->next; + file_count++; + } + + if ((file_count == 0) || !found_good) + { + sleep(1); + printf("Bad file count, retrying"); + found_good = false; + found_bad = false; + continue; + } + else + { + break; + } + } + + ASSERT_EQ_(found_good, 1, "Created file not found"); + ASSERT_EQ_(found_bad, 0, "Filter found file it shouldn't"); + res = ms3_delete(ms3, s3bucket, "test/prefix.txt"); + ASSERT_EQ(res, 0); + res = ms3_delete(ms3, s3bucket, "other/prefix.txt"); + ASSERT_EQ(res, 0); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/small_buffer.c b/storage/maria/libmarias3/tests/small_buffer.c new file mode 100644 index 00000000..4e9900b4 --- /dev/null +++ b/storage/maria/libmarias3/tests/small_buffer.c @@ -0,0 +1,98 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic GET with a small buffer */ + +int main(int argc, char *argv[]) +{ + int res; + uint8_t *data; + size_t length; + size_t new_buffer_size; + ms3_st *ms3; + char *test_string = malloc(64 * 1024); + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + memset(test_string, 'a', 64 * 1024); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(true); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "test/small_buffer.dat", + (const uint8_t *)test_string, + 64 * 1024); + ASSERT_EQ_(res, 0, "Result: %u", res); + new_buffer_size = 64 * 1024; + res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size); + ASSERT_EQ_(res, 0, "Result: %u", res); + res = ms3_get(ms3, s3bucket, "test/small_buffer.dat", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 64 * 1024); + ms3_free(data); + + new_buffer_size = 1024; + res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size); + ASSERT_EQ_(res, 0, "Result: %u", res); + res = ms3_get(ms3, s3bucket, "test/small_buffer.dat", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 64 * 1024); + res = ms3_delete(ms3, s3bucket, "test/small_buffer.dat"); + ASSERT_EQ_(res, 0, "Result: %u", res); + free(test_string); + ms3_free(data); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} diff --git a/storage/maria/libmarias3/tests/snowman.c b/storage/maria/libmarias3/tests/snowman.c new file mode 100644 index 00000000..cd611c7d --- /dev/null +++ b/storage/maria/libmarias3/tests/snowman.c @@ -0,0 +1,180 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * Copyright 2019 MariaDB Corporation Ab. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include <yatl/lite.h> +#include <libmarias3/marias3.h> + +/* Tests basic calls using UTF-8 */ + +int main(int argc, char *argv[]) +{ + int res; + ms3_list_st *list = NULL, *list_it = NULL; + uint8_t *data; + size_t length; + int i; + bool found; + uint8_t list_version; + const char *test_string = "Another ☃☃☃ bites the dust"; + ms3_status_st status; + ms3_st *ms3; + char *s3key = getenv("S3KEY"); + char *s3secret = getenv("S3SECRET"); + char *s3region = getenv("S3REGION"); + char *s3bucket = getenv("S3BUCKET"); + char *s3host = getenv("S3HOST"); + char *s3noverify = getenv("S3NOVERIFY"); + char *s3usehttp = getenv("S3USEHTTP"); + char *s3port = getenv("S3PORT"); + + SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); + SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); + SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); + SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); + + (void) argc; + (void) argv; + + ms3_library_init(); + ms3 = ms3_init(s3key, s3secret, s3region, s3host); + + if (s3noverify && !strcmp(s3noverify, "1")) + { + ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); + } + + if (s3usehttp && !strcmp(s3usehttp, "1")) + { + ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); + } + + if (s3port) + { + int port = atol(s3port); + ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); + } + +// ms3_debug(); + ASSERT_NOT_NULL(ms3); + + res = ms3_put(ms3, s3bucket, "☃/☃.☃", + (const uint8_t *)test_string, + strlen(test_string)); + ASSERT_EQ_(res, 0, "Result: %u", res); + + // A prefix that will give no results; + res = ms3_list(ms3, s3bucket, "asdfghjkl", &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_NULL_(list, "List not empty"); + + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "☃/☃.☃", 11)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 32, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + // Retry list with V1 API + list_version = 1; + list = NULL; + ms3_set_option(ms3, MS3_OPT_FORCE_LIST_VERSION, &list_version); + res = ms3_list(ms3, s3bucket, NULL, &list); + ASSERT_EQ_(res, 0, "Result: %u", res); + found = false; + list_it = list; + + while (list_it) + { + if (!strncmp(list_it->key, "☃/☃.☃", 11)) + { + found = true; + break; + } + + list_it = list_it->next; + } + + ASSERT_EQ_(found, 1, "Created file not found"); + + if (list_it) + { + ASSERT_EQ_(list_it->length, 32, "Created file is unexpected length"); + ASSERT_NEQ_(list_it->created, 0, "Created file timestamp is bad"); + } + else + { + ASSERT_TRUE_(false, "No resuts from list"); + } + + res = ms3_get(ms3, s3bucket, "☃/☃.☃", &data, &length); + ASSERT_EQ_(res, 0, "Result: %u", res); + ASSERT_EQ(length, 32); + ASSERT_STREQ((char *)data, test_string); + + for (i = 0; i <= 3; i++) + { + res = ms3_status(ms3, s3bucket, "☃/☃.☃", &status); + + if (res == MS3_ERR_NOT_FOUND) + { + continue; + } + + ASSERT_EQ_(res, 0, "Result: %u", res); + + if (res == 0) + { + break; + } + } + + ASSERT_EQ(status.length, 32); + ASSERT_NEQ(status.created, 0); + res = ms3_delete(ms3, s3bucket, "☃/☃.☃"); + ASSERT_EQ_(res, 0, "Result: %u", res); + ms3_free(data); + res = ms3_get(ms3, s3bucket, "☃/☃.☃", &data, &length); + ASSERT_NEQ_(res, 0, "Object should error"); + ASSERT_NULL_(data, "Data should be NULL"); + ASSERT_EQ_(length, 0, "There should be no data"); + ms3_deinit(ms3); + ms3_library_deinit(); + return 0; +} |