提交 fc2b8ddd 编写于 作者: M Maxim Polyakov

Fixed a various warnings

Signed-off-by: NMaxim Polyakov <polyakov.maksim@huawei.com>
上级 07820e42
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
......@@ -33,7 +48,8 @@ static const size_t allocs_sizes[ALLOCATIONS_NUMBER] = {
2 * 1024 * 1024,
8 * 1024 * 1024,
16 * 1024 * 1024,
32 * 1024 * 1024};
32 * 1024 * 1024
};
void iterate_callback(void *base, size_t size, void *data)
{
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test-malloc-stats-common.h"
static int stats_from_mallinfo(malloc_thread_stats_t *stats, long long *total_free_heap_space, int use_mallinfo2)
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_ITERATE_DISABLE_COMMON_H
#define TEST_ITERATE_DISABLE_COMMON_H
......@@ -7,12 +22,15 @@ int check_and_report(const char *message, int (*check_func)(void))
{
t_printf("%s...", message);
int ret = check_func();
if (ret == 0) {
if (ret == 0)
{
t_printf("Success\n");
} else {
}
else
{
t_error("Failed\n");
}
return ret;
}
#endif //TEST_ITERATE_DISABLE_COMMON_H
\ No newline at end of file
#endif // TEST_ITERATE_DISABLE_COMMON_H
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <malloc.h>
#include "test-malloc-api-common.h"
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_MALLOC_STATS_H
#define TEST_MALLOC_STATS_H
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include "test-malloc-info-stats-print.h"
......@@ -27,8 +42,7 @@ static const xmlChar *get_attribute(const char *attr_name, xmlNodePtr node)
return NULL;
}
static xmlNodePtr
find_child_node_with_attr(const char *name, const char *attr_name, const char *attr_value, xmlNodePtr parent)
static xmlNodePtr find_child_node_with_attr(const char *name, const char *attr_name, const char *attr_value, xmlNodePtr parent)
{
if (parent == NULL)
{
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_MALLOC_STATS_COMMON_H
#define TEST_MALLOC_STATS_COMMON_H
......@@ -11,27 +26,34 @@
#include "test.h"
#define SIZES_COUNT 11
#define SIZE_ALIGN (8*sizeof(size_t))
#define MMAP_THRESHOLD ((0x1c00*SIZE_ALIGN) - OVERHEAD)
#define LIST_OVERHEAD (2*sizeof(void*))
#define OVERHEAD (2*sizeof(size_t) + sizeof(void*) + LIST_OVERHEAD)
#define SIZE_ALIGN (8 * sizeof(size_t))
#define MMAP_THRESHOLD ((0x1c00 * SIZE_ALIGN) - OVERHEAD)
#define LIST_OVERHEAD (2 * sizeof(void *))
#define OVERHEAD (2 * sizeof(size_t) + sizeof(void *) + LIST_OVERHEAD)
static size_t sizes[SIZES_COUNT] = {
23, 32,
256, 3072,
3584, 229376,
262144, 327680,
8 * 1024 * 1024,16 * 1024 * 1024,
23,
32,
256,
3072,
3584,
229376,
262144,
327680,
8 * 1024 * 1024,
16 * 1024 * 1024,
32 * 1024 * 1024
};
typedef struct {
typedef struct
{
long long mmapped_regions;
long long total_mmapped_memory;
long long total_allocated_memory;
} malloc_thread_stats_t;
typedef struct {
typedef struct
{
size_t alloc_size;
pthread_barrier_t *alloc_barrier;
pthread_barrier_t *free_barrier;
......@@ -41,8 +63,10 @@ typedef struct {
static malloc_thread_stats_t get_total_from_test_sizes()
{
malloc_thread_stats_t total_stats = {0};
for (size_t i = 0; i < SIZES_COUNT; i++) {
if (sizes[i] > MMAP_THRESHOLD) {
for (size_t i = 0; i < SIZES_COUNT; i++)
{
if (sizes[i] > MMAP_THRESHOLD)
{
total_stats.total_mmapped_memory += sizes[i];
total_stats.mmapped_regions++;
}
......@@ -53,7 +77,8 @@ static malloc_thread_stats_t get_total_from_test_sizes()
static int expect_greater_equal(long long amt1, long long amt2, const char *amt1_name, const char *amt2_name)
{
if (amt1 >= amt2) {
if (amt1 >= amt2)
{
return 1;
}
t_error("Expected %s(value: %lld) to be >= %s(value: %lld)\n", amt1_name, amt1, amt2_name, amt2);
......@@ -62,7 +87,8 @@ static int expect_greater_equal(long long amt1, long long amt2, const char *amt1
static int expect_equal(long long amt, long long value, const char *amt_name)
{
if (amt == value) {
if (amt == value)
{
return 1;
}
t_error("Expected %s(value: %lld) to be %lld\n", amt_name, amt, value);
......@@ -77,23 +103,20 @@ static int validate_total_allocated(malloc_thread_stats_t *total_stats)
total_stats->total_allocated_memory,
total_from_test_sizes.total_allocated_memory,
"allocated memory",
"total memory from test sizes"
);
"total memory from test sizes");
result &= expect_greater_equal(
total_stats->total_mmapped_memory,
total_from_test_sizes.total_mmapped_memory,
"mmapped memory",
"total large memory from test sizes"
);
"total large memory from test sizes");
result &= expect_equal(
total_stats->mmapped_regions,
total_from_test_sizes.mmapped_regions,
"mmapped regions"
);
"mmapped regions");
return result;
}
static int validate_all_freed(malloc_thread_stats_t *total_stats)
static int validate_all_freed(malloc_thread_stats_t *total_stats)
{
int result = expect_equal(total_stats->total_allocated_memory, 0, "allocated memory");
result &= expect_equal(total_stats->total_mmapped_memory, 0, "mmapped memory");
......@@ -112,4 +135,4 @@ static void *allocate_wait_free(void *arg)
return NULL;
}
#endif //TEST_MALLOC_STATS_COMMON_H
#endif // TEST_MALLOC_STATS_COMMON_H
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "test-malloc-info-stats-print.h"
static void stderr_stats_cb(void)
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <malloc.h>
#include "test-malloc-api-common.h"
......
#ifndef _MALLOC_H
#define _MALLOC_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -10,7 +12,6 @@ extern "C" {
#define __NEED_uintptr_t
#include <bits/alltypes.h>
#include <stdio.h>
void *malloc (size_t);
void *calloc (size_t, size_t);
......
......@@ -107,7 +107,6 @@ static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, ch
#endif
libc.initialized = 1;
/* Pass control to the application */
exit(main(argc, argv, envp));
return 0;
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdarg.h>
#include <malloc.h>
#include <errno.h>
#include <string.h>
#include "pthread_impl.h"
#include "malloc_impl.h"
......@@ -27,8 +43,11 @@ static void stat_printf(write_cb_fun *write_cb, void *write_cb_arg, const char *
va_list args;
va_start(args, fmt);
char buf[STAT_PRINTF_MAX_LEN + 1];
vsnprintf(buf, STAT_PRINTF_MAX_LEN, fmt, args);
write_cb(write_cb_arg, buf);
if (vsnprintf(buf, STAT_PRINTF_MAX_LEN, fmt, args)) {
write_cb(write_cb_arg, buf);
} else {
fprintf(stderr, "Error writing to buffer");
}
va_end(args);
}
......@@ -175,7 +194,9 @@ static void print_total_free_heap_space(
static void print_to_file(void *fp, const char *s)
{
fputs(s, fp);
if (fputs(s, fp) == EOF) {
fprintf(stderr, "Error writing to file stream: %s", strerror(errno));
}
}
static void add_stats(malloc_stats_t *destination, const malloc_stats_t *source)
......
#include "pthread_impl.h"
#include <threads.h>
static void *__pthread_getspecific(pthread_key_t k)
{
struct pthread *self = __pthread_self();
return self->tsd[k];
}
weak_alias(__pthread_getspecific, pthread_getspecific);
weak_alias(__pthread_getspecific, tss_get);
#include "pthread_impl.h"
int pthread_setspecific(pthread_key_t k, const void *x)
{
struct pthread *self = __pthread_self();
/* Avoid unnecessary COW */
if (self->tsd[k] != x) {
self->tsd[k] = (void *)x;
self->tsd_used = 1;
}
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册