diff options
| author | Demitri Swan <demitris@bu.edu> | 2020-08-31 07:57:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-31 07:57:59 -0700 |
| commit | 0c1e5347bf24003e43ca1eec9e28bf1ebec75aa9 (patch) | |
| tree | 04bf336c930c7f9122dfbc473c697d2513e3de6b | |
| parent | 171221f0e79528b5110d0e470e88cc697d26f83f (diff) | |
Support GCC-10 in CI and prom,promhttp,promtest (#25)
Co-authored-by: Eldar Yusupov <eyusupov@gmail.com>
| -rw-r--r-- | .github/workflows/ci.yaml | 15 | ||||
| -rwxr-xr-x | auto | 3 | ||||
| -rwxr-xr-x | autolib/cmd/dev | 20 | ||||
| -rw-r--r-- | autolib/docker.sh | 51 | ||||
| -rw-r--r-- | prom/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | prom/include/prom_collector_registry.h | 4 | ||||
| -rw-r--r-- | prom/include/prom_histogram_buckets.h | 2 | ||||
| -rw-r--r-- | prom/src/prom_collector_registry.c | 1 | ||||
| -rw-r--r-- | prom/src/prom_histogram_buckets.c | 4 | ||||
| -rw-r--r-- | prom/src/prom_metric_t.h | 2 | ||||
| -rw-r--r-- | prom/src/prom_process_fds.c | 4 | ||||
| -rw-r--r-- | prom/src/prom_process_fds_t.h | 4 | ||||
| -rw-r--r-- | prom/src/prom_process_limits.c | 4 | ||||
| -rw-r--r-- | prom/src/prom_process_limits_t.h | 10 | ||||
| -rw-r--r-- | prom/src/prom_process_stat.c | 6 | ||||
| -rw-r--r-- | prom/src/prom_process_stat_t.h | 8 | ||||
| -rw-r--r-- | promhttp/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | promtest/test/promtest_counter.c | 47 | ||||
| -rw-r--r-- | promtest/test/promtest_counter.h | 4 | ||||
| -rw-r--r-- | promtest/test/promtest_gauge.c | 44 | ||||
| -rw-r--r-- | promtest/test/promtest_gauge.h | 4 | ||||
| -rw-r--r-- | promtest/test/promtest_helpers.c | 28 | ||||
| -rw-r--r-- | promtest/test/promtest_helpers.h | 8 |
23 files changed, 187 insertions, 90 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 75bc551..513f47d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,6 +5,16 @@ on: - pull_request jobs: + ubuntu-20-04: + name: ubuntu-20-04 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: test + env: + DOCKER_IMAGE: ubuntu:20.04 + CI: 1 + run: make ubuntu-18-04: name: ubuntu-18-04 runs-on: ubuntu-latest @@ -13,6 +23,7 @@ jobs: - name: test env: DOCKER_IMAGE: ubuntu:18.04 + CI: 1 run: make ubuntu-16-04: name: ubuntu-16-04 @@ -22,6 +33,7 @@ jobs: - name: test env: DOCKER_IMAGE: ubuntu:16.04 + CI: 1 run: make debian-buster: name: debian-buster @@ -31,6 +43,7 @@ jobs: - name: test env: DOCKER_IMAGE: debian:buster + CI: 1 run: make debian-stretch: name: debian-stretch @@ -40,6 +53,7 @@ jobs: - name: test env: DOCKER_IMAGE: debian:stretch + CI: 1 run: make debian-jessie: name: debian-jessie @@ -49,4 +63,5 @@ jobs: - name: test env: DOCKER_IMAGE: debian:jessie + CI: 1 run: make
\ No newline at end of file @@ -12,6 +12,9 @@ fi export PROJECT_ROOT=$(pushd $(dirname $0) > /dev/null; echo $PWD; popd > /dev/null) export DOCKER_IMAGE +export CI=${CI:=0} +export CC=/usr/bin/gcc + PROGRAM_NAME="$(basename $0)" usage(){ diff --git a/autolib/cmd/dev b/autolib/cmd/dev index bcbf35f..8025993 100755 --- a/autolib/cmd/dev +++ b/autolib/cmd/dev @@ -75,6 +75,9 @@ run(){ args+=(--security-opt seccomp=unconfined) # Required for debugging args+=(--publish $DOCKER_PORT:$DOCKER_PORT) # map DOCKER_PORT to the host args+=(--rm) # Remove when done + if (( ${CI} == 0 )); then + args+=(--tty) + fi echo ${args[@]} docker run ${args[@]} prometheus-client-c-dev ${DOCKER_EXEC} ${DOCKER_EXEC_ARGS[@]} @@ -103,4 +106,19 @@ main(){ run $@; exit $? } -[[ $BASH_SOURCE == $0 ]] && main $@
\ No newline at end of file +[[ $BASH_SOURCE == $0 ]] && main $@ + +# curl -L -o /tmp/gcc-${GCC_VERSION}.tar.xz https://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz && \ +# tar xf /tmp/gcc-${GCC_VERSION}.tar.xz -C /tmp && \ +# rm -rf /tmp/gcc-${GCC_VERSION}.tar.xz && \ +# cd /tmp/gcc-${GCC_VERSION} && \ +# contrib/download_prerequisites && \ +# ./configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc --enable-checking=release --enable-languages=c --disable-multilib && \ +# make && \ +# make install-strip && \ +# cd $OLDPWD && \ +# echo 'export PATH=/usr/local/gcc/bin:$PATH' >> /root/.bashrc && \ +# echo 'LD_LIBRARY_PATH=/usr/local/gcc/lib64:$LD_LIBRARY_PATH' >> /root/.bashrc && \ +# curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz | tar xzf - -C /opt && \ +# cp /opt/cmake-${CMAKE_VERSION}-Linux-x86_64/bin/* /usr/local/bin/ && \ +# cp -R /opt/cmake-${CMAKE_VERSION}-Linux-x86_64/share/cmake-3.14 /usr/local/share/ && \
\ No newline at end of file diff --git a/autolib/docker.sh b/autolib/docker.sh index bfef40d..9834c4b 100644 --- a/autolib/docker.sh +++ b/autolib/docker.sh @@ -5,11 +5,46 @@ source "${lib}/output.sh" PROJECT_ROOT=$(pushd "$(dirname ${BASH_SOURCE[0]})/.." > /dev/null; echo $PWD; popd > /dev/null) -autolib_debian_template(){ +autolib_new_debian_template(){ cat <<'EOF' FROM __DOCKER_IMAGE__ -RUN apt-get update && \ +RUN set -x && \ + apt-get update && \ + apt-get install -y apt-utils software-properties-common && \ + add-apt-repository ppa:ubuntu-toolchain-r/test && \ + apt-get update -y && \ + apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc-10 libmicrohttpd-dev doxygen graphviz && \ + rm -f /usr/bin/gcc && \ + ln -s /usr/bin/gcc-10 /usr/bin/gcc && \ + curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt && \ + cp /opt/cmake-3.14.5-Linux-x86_64/bin/* /usr/local/bin/ && \ + cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/ && \ + curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz 2> /dev/null | tar xzf - -C /usr/local && \ + mkdir -p /gopath/{src,bin} && \ + printf 'export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n' > /root/.bash_profile && \ + printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint && \ + chmod +x /entrypoint && \ + GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json && \ + GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json && \ + GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog && \ + GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /code +ENTRYPOINT ["/entrypoint"] + +EOF +} + +autolib_old_debian_template(){ + cat <<'EOF' +FROM __DOCKER_IMAGE__ + +ENV GCC_VERSION 10.1.0 + +RUN set -x && \ + apt-get update && \ apt-get install -y apt-utils && \ apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc libmicrohttpd-dev doxygen graphviz && \ curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt && \ @@ -36,14 +71,20 @@ autolib_write_dockerfile(){ local docker_image="$1" local r case "$docker_image" in - ( ubuntu:18.04 | ubuntu:16.04 | debian:buster | debian:stretch | debian:jessie ) { - autolib_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || { + ( ubuntu:20.04 | ubuntu:18.04 ) { + autolib_new_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || { + r=$? + autolib_output_error "failed to generate dockerfile" + return $r + } + } ;; + ( ubuntu:16.04 | debian:buster | debian:stretch | debian:jessie ) { + autolib_old_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || { r=$? autolib_output_error "failed to generate dockerfile" return $r } } ;; - ( * ) { r=1 autolib_output_error "unsupported DOCKER_IMAGE: $docker_image" diff --git a/prom/CMakeLists.txt b/prom/CMakeLists.txt index b99cd75..6ed20b6 100644 --- a/prom/CMakeLists.txt +++ b/prom/CMakeLists.txt @@ -106,6 +106,7 @@ include(FindThreads) add_library(prom SHARED) target_compile_options(prom PRIVATE "-Werror" "-Wuninitialized" "-Wall" "-Wno-unused-label" "-std=gnu11") +target_compile_options(prom PUBLIC "-Werror" "-Wuninitialized" "-Wall" "-Wno-unused-label" "-std=gnu11") target_include_directories( prom diff --git a/prom/include/prom_collector_registry.h b/prom/include/prom_collector_registry.h index 8e70c92..974aa24 100644 --- a/prom/include/prom_collector_registry.h +++ b/prom/include/prom_collector_registry.h @@ -34,7 +34,7 @@ typedef struct prom_collector_registry prom_collector_registry_t; * @brief Initialize the default registry by calling prom_collector_registry_init within your program. You MUST NOT * modify this value. */ -prom_collector_registry_t *PROM_COLLECTOR_REGISTRY_DEFAULT; +extern prom_collector_registry_t *PROM_COLLECTOR_REGISTRY_DEFAULT; /** * @brief Initializes the default collector registry and enables metric collection on the executing process @@ -120,4 +120,4 @@ const char* prom_collector_registry_bridge(prom_collector_registry_t *self); int prom_collector_registry_validate_metric_name(prom_collector_registry_t *self, const char *metric_name); -#endif // PROM_H
\ No newline at end of file +#endif // PROM_H diff --git a/prom/include/prom_histogram_buckets.h b/prom/include/prom_histogram_buckets.h index ec850e2..24afe22 100644 --- a/prom/include/prom_histogram_buckets.h +++ b/prom/include/prom_histogram_buckets.h @@ -41,7 +41,7 @@ prom_histogram_buckets_t* prom_histogram_buckets_new(size_t count, double bucket /** * @brief the default histogram buckets: .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10 */ -prom_histogram_buckets_t *prom_histogram_default_buckets; +extern prom_histogram_buckets_t *prom_histogram_default_buckets; /** *@brief Construct a linearly sized prom_histogram_buckets_t* diff --git a/prom/src/prom_collector_registry.c b/prom/src/prom_collector_registry.c index 166c239..aa69489 100644 --- a/prom/src/prom_collector_registry.c +++ b/prom/src/prom_collector_registry.c @@ -37,6 +37,7 @@ #include "prom_process_limits_i.h" #include "prom_string_builder_i.h" +prom_collector_registry_t *PROM_COLLECTOR_REGISTRY_DEFAULT; prom_collector_registry_t* prom_collector_registry_new(const char *name) { diff --git a/prom/src/prom_histogram_buckets.c b/prom/src/prom_histogram_buckets.c index ecfd00c..f63f7ae 100644 --- a/prom/src/prom_histogram_buckets.c +++ b/prom/src/prom_histogram_buckets.c @@ -25,6 +25,8 @@ #include "prom_assert.h" #include "prom_log.h" +prom_histogram_buckets_t *prom_histogram_default_buckets; + prom_histogram_buckets_t* prom_histogram_buckets_new(size_t count, double bucket, ...) { prom_histogram_buckets_t *self = (prom_histogram_buckets_t*) prom_malloc(sizeof(prom_histogram_buckets_t)); double *upper_bounds = (double*) prom_malloc(sizeof(double)*count); @@ -98,4 +100,4 @@ int prom_histogram_buckets_destroy(prom_histogram_buckets_t *self) { size_t prom_histogram_buckets_count(prom_histogram_buckets_t *self) { PROM_ASSERT(self != NULL); return self->count; -}
\ No newline at end of file +} diff --git a/prom/src/prom_metric_t.h b/prom/src/prom_metric_t.h index cab93d6..17e0847 100644 --- a/prom/src/prom_metric_t.h +++ b/prom/src/prom_metric_t.h @@ -42,7 +42,7 @@ typedef enum prom_metric_type { /** * @brief API PRIVATE Maps metric type constants to human readable string values */ -char *prom_metric_type_map[4]; +extern char *prom_metric_type_map[4]; /** * @brief API PRIVATE An opaque struct to users containing metric metadata; one or more metric samples; and a metric formatter diff --git a/prom/src/prom_process_fds.c b/prom/src/prom_process_fds.c index c8a5f4e..4451782 100644 --- a/prom/src/prom_process_fds.c +++ b/prom/src/prom_process_fds.c @@ -30,6 +30,8 @@ #include "prom_log.h" #include "prom_process_fds_t.h" +prom_gauge_t *prom_process_open_fds; + int prom_process_fds_count(const char *path) { int count = 0; int r = 0; @@ -74,4 +76,4 @@ int prom_process_fds_init(void) { 0, NULL ); return 0; -}
\ No newline at end of file +} diff --git a/prom/src/prom_process_fds_t.h b/prom/src/prom_process_fds_t.h index d7f3e2b..e0e73c6 100644 --- a/prom/src/prom_process_fds_t.h +++ b/prom/src/prom_process_fds_t.h @@ -19,6 +19,6 @@ #ifndef PROM_PROESS_FDS_T_H #define PROM_PROESS_FDS_T_H -prom_gauge_t *prom_process_open_fds; +extern prom_gauge_t *prom_process_open_fds; -#endif // PROM_PROESS_FDS_T_H
\ No newline at end of file +#endif // PROM_PROESS_FDS_T_H diff --git a/prom/src/prom_process_limits.c b/prom/src/prom_process_limits.c index 685a31c..fcc8649 100644 --- a/prom/src/prom_process_limits.c +++ b/prom/src/prom_process_limits.c @@ -49,6 +49,10 @@ typedef enum prom_process_limit_rdp_limit_type { PROM_PROCESS_LIMITS_RDP_HARD } prom_process_limit_rdp_limit_type_t; +prom_gauge_t *prom_process_virtual_memory_max_bytes; +prom_gauge_t *prom_process_resident_memory_bytes; +prom_gauge_t *prom_process_max_fds; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // prom_process_limits_row_t diff --git a/prom/src/prom_process_limits_t.h b/prom/src/prom_process_limits_t.h index 9435a8b..b18253d 100644 --- a/prom/src/prom_process_limits_t.h +++ b/prom/src/prom_process_limits_t.h @@ -21,10 +21,10 @@ #include "prom_procfs_t.h" -prom_gauge_t *prom_process_open_fds; -prom_gauge_t *prom_process_max_fds; -prom_gauge_t *prom_process_virtual_memory_max_bytes; -prom_gauge_t *prom_process_resident_memory_bytes; +extern prom_gauge_t *prom_process_open_fds; +extern prom_gauge_t *prom_process_max_fds; +extern prom_gauge_t *prom_process_virtual_memory_max_bytes; +extern prom_gauge_t *prom_process_resident_memory_bytes; typedef struct prom_process_limits_row { @@ -43,4 +43,4 @@ typedef struct prom_process_limits_current_row { typedef prom_procfs_buf_t prom_process_limits_file_t; -#endif // PROM_PROCESS_T_H
\ No newline at end of file +#endif // PROM_PROCESS_T_H diff --git a/prom/src/prom_process_stat.c b/prom/src/prom_process_stat.c index 9deb717..7a1833c 100644 --- a/prom/src/prom_process_stat.c +++ b/prom/src/prom_process_stat.c @@ -28,6 +28,10 @@ #include "prom_process_stat_t.h" #include "prom_procfs_i.h" +prom_gauge_t *prom_process_cpu_seconds_total; +prom_gauge_t *prom_process_virtual_memory_bytes; +prom_gauge_t *prom_process_start_time_seconds; + prom_process_stat_file_t* prom_process_stat_file_new(const char *path) { if (path) { return prom_procfs_buf_new(path); @@ -195,4 +199,4 @@ int prom_process_stats_init(void) { 0, NULL ); return 0; -}
\ No newline at end of file +} diff --git a/prom/src/prom_process_stat_t.h b/prom/src/prom_process_stat_t.h index e9c6a7c..a26ecda 100644 --- a/prom/src/prom_process_stat_t.h +++ b/prom/src/prom_process_stat_t.h @@ -22,9 +22,9 @@ #include "prom_procfs_t.h" -prom_gauge_t *prom_process_cpu_seconds_total; -prom_gauge_t *prom_process_virtual_memory_bytes; -prom_gauge_t *prom_process_start_time_seconds; +extern prom_gauge_t *prom_process_cpu_seconds_total; +extern prom_gauge_t *prom_process_virtual_memory_bytes; +extern prom_gauge_t *prom_process_start_time_seconds; /** * @brief Refer to man proc and search for /proc/[pid]/stat @@ -86,4 +86,4 @@ typedef struct prom_process_stat { typedef prom_procfs_buf_t prom_process_stat_file_t; -#endif // PROM_PROCESS_STATS_T_H
\ No newline at end of file +#endif // PROM_PROCESS_STATS_T_H diff --git a/promhttp/CMakeLists.txt b/promhttp/CMakeLists.txt index 8283a21..5a14903 100644 --- a/promhttp/CMakeLists.txt +++ b/promhttp/CMakeLists.txt @@ -59,6 +59,9 @@ target_sources( find_library(prom prom HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../prom/build) find_library(microhttpd microhttpd) +target_compile_options(promhttp PRIVATE "-Werror" "-Wuninitialized" "-Wall" "-Wno-unused-label" "-std=gnu11") +target_compile_options(promhttp PUBLIC "-Werror" "-Wuninitialized" "-Wall" "-Wno-unused-label" "-std=gnu11") + target_link_libraries(promhttp PUBLIC Threads::Threads prom microhttpd) set(CPACK_PACKAGE_NAME libpromhttp-dev) diff --git a/promtest/test/promtest_counter.c b/promtest/test/promtest_counter.c index c57cd56..923c8a2 100644 --- a/promtest/test/promtest_counter.c +++ b/promtest/test/promtest_counter.c @@ -14,22 +14,23 @@ * limitations under the License. */ +#include "promtest_counter.h" + #include <pthread.h> #include "parson.h" -#include "unity.h" - #include "prom.h" #include "promhttp.h" #include "promtest_helpers.h" -#include "promtest_counter.h" - +#include "unity.h" static void *promtest_counter_handler(void *data); static int promtest_parse_counter_output(const char *output, char **value); +prom_counter_t *foo_counter; /** - * @brief For each thread in a threadpool of 10 we increment a single counter 1 million times + * @brief For each thread in a threadpool of 10 we increment a single counter 1 + * million times * * The purpose of this test is to check for deadlock and race conditions */ @@ -43,21 +44,22 @@ void promtest_counter(void) { // Start each thread for (int i = 0; i < PROMTEST_THREAD_POOL_SIZE; i++) { - if (pthread_create(&(thread_pool[i]), NULL, promtest_counter_handler, NULL)) { + if (pthread_create(&(thread_pool[i]), NULL, promtest_counter_handler, + NULL)) { TEST_FAIL_MESSAGE("failed to create thread"); } } // Join each thread for (int i = 0; i < PROMTEST_THREAD_POOL_SIZE; i++) { - if (pthread_join(thread_pool[i], (void**) &(retvals[i]))) { + if (pthread_join(thread_pool[i], (void **)&(retvals[i]))) { TEST_FAIL_MESSAGE("thread failed to join"); } } // verify clean exit for each thread for (int i = 0; i < PROMTEST_THREAD_POOL_SIZE; i++) { - if (*((int *) retvals[i]) != 0) { + if (*((int *)retvals[i]) != 0) { TEST_FAIL_MESSAGE("thread did not exit properly"); } } @@ -78,7 +80,7 @@ void promtest_counter(void) { } // Parse the output - char *value = (char *) malloc(sizeof(char)*100); + char *value = (char *)malloc(sizeof(char) * 100); if (promtest_parse_counter_output(output, &value)) { TEST_FAIL_MESSAGE("failed to parse output"); } @@ -97,22 +99,25 @@ int promtest_counter_setup(void) { prom_collector_registry_default_init(); // Set the counter - foo_counter = prom_collector_registry_must_register_metric(prom_counter_new( - "foo_counter", "counter for foo", 0, NULL - )); + foo_counter = prom_collector_registry_must_register_metric( + prom_counter_new("foo_counter", "counter for foo", 0, NULL)); // Set the collector registry on the handler to the default registry promhttp_set_active_collector_registry(NULL); // Start the HTTP server - promtest_daemon = promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL); + promtest_daemon = + promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL); - if (promtest_daemon == NULL) return 1; - else return 0; + if (promtest_daemon == NULL) + return 1; + else + return 0; } int promtest_counter_teardown(void) { - // Destroy the default registry. This effectively deallocates all metrics registered to it, including itself + // Destroy the default registry. This effectively deallocates all metrics + // registered to it, including itself prom_collector_registry_destroy(PROM_COLLECTOR_REGISTRY_DEFAULT); PROM_COLLECTOR_REGISTRY_DEFAULT = NULL; @@ -122,7 +127,6 @@ int promtest_counter_teardown(void) { return 0; } - /** * @brief The entrypoint to a worker thread within the prom_counter_test */ @@ -130,9 +134,9 @@ static void *promtest_counter_handler(void *data) { for (int i = 0; i < 1000000; i++) { prom_counter_inc(foo_counter, NULL); } - int *retval = (int*) malloc(sizeof(int)); + int *retval = (int *)malloc(sizeof(int)); *retval = 0; - return (void*) retval; + return (void *)retval; } /** @@ -165,14 +169,14 @@ static int promtest_parse_counter_output(const char *output, char **value) { if (samples == NULL) { TEST_FAIL_MESSAGE("failed to retrieve metrics from JSON_Object"); } - if (json_array_get_count(samples) < 1){ + if (json_array_get_count(samples) < 1) { TEST_FAIL_MESSAGE("No samples found"); } JSON_Object *sample = json_array_get_object(samples, 0); if (sample == NULL) { TEST_FAIL_MESSAGE("failed to get metric sample"); } - *value = (char *) json_object_get_string(sample, "value"); + *value = (char *)json_object_get_string(sample, "value"); break; } if (strlen(*value) == 0) { @@ -180,4 +184,3 @@ static int promtest_parse_counter_output(const char *output, char **value) { } return 0; } - diff --git a/promtest/test/promtest_counter.h b/promtest/test/promtest_counter.h index a8fd719..a94817a 100644 --- a/promtest/test/promtest_counter.h +++ b/promtest/test/promtest_counter.h @@ -19,11 +19,11 @@ #ifndef PROMTEST_COUNTER_H #define PROMTEST_COUNTER_H -prom_counter_t *foo_counter; +extern prom_counter_t *foo_counter; int promtest_counter_setup(void); int promtest_counter_teardown(void); void promtest_counter(void); -#endif // PROMTEST_COUNTER_H
\ No newline at end of file +#endif // PROMTEST_COUNTER_H
\ No newline at end of file diff --git a/promtest/test/promtest_gauge.c b/promtest/test/promtest_gauge.c index c33450d..fd6244d 100644 --- a/promtest/test/promtest_gauge.c +++ b/promtest/test/promtest_gauge.c @@ -14,22 +14,23 @@ * limitations under the License. */ +#include "promtest_gauge.h" + #include <pthread.h> #include "parson.h" -#include "unity.h" - #include "prom.h" #include "promhttp.h" #include "promtest_helpers.h" -#include "promtest_gauge.h" - +#include "unity.h" static void *promtest_gauge_handler(void *data); static int promtest_parse_gauge_output(const char *output, char **value); +prom_gauge_t *foo_gauge; /** - * @brief For each thread in a threadpool of 10 we increment a single gauge 1 million times + * @brief For each thread in a threadpool of 10 we increment a single gauge 1 + * million times * * The purpose of this test is to check for deadlock and race conditions */ @@ -50,14 +51,14 @@ void promtest_gauge(void) { // Join each thread for (int i = 0; i < PROMTEST_THREAD_POOL_SIZE; i++) { - if (pthread_join(thread_pool[i], (void**) &(retvals[i]))) { + if (pthread_join(thread_pool[i], (void **)&(retvals[i]))) { TEST_FAIL_MESSAGE("thread failed to join"); } } // verify clean exit for each thread for (int i = 0; i < PROMTEST_THREAD_POOL_SIZE; i++) { - if (*((int *) retvals[i]) != 0) { + if (*((int *)retvals[i]) != 0) { TEST_FAIL_MESSAGE("thread did not exit properly"); } } @@ -78,7 +79,7 @@ void promtest_gauge(void) { } // Parse the output - char *value = (char *) malloc(sizeof(char)*100); + char *value = (char *)malloc(sizeof(char) * 100); if (promtest_parse_gauge_output(output, &value)) { TEST_FAIL_MESSAGE("failed to parse output"); } @@ -97,22 +98,25 @@ int promtest_gauge_setup(void) { prom_collector_registry_default_init(); // Set the gauge - foo_gauge = prom_collector_registry_must_register_metric(prom_gauge_new( - "foo_gauge", "gauge for foo", 0, NULL - )); + foo_gauge = prom_collector_registry_must_register_metric( + prom_gauge_new("foo_gauge", "gauge for foo", 0, NULL)); // Set the collector registry on the handler to the default registry promhttp_set_active_collector_registry(NULL); // Start the HTTP server - promtest_daemon = promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL); + promtest_daemon = + promhttp_start_daemon(MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL); - if (promtest_daemon == NULL) return 1; - else return 0; + if (promtest_daemon == NULL) + return 1; + else + return 0; } int promtest_gauge_teardown(void) { - // Destroy the default registry. This effectively deallocates all metrics registered to it, including itself + // Destroy the default registry. This effectively deallocates all metrics + // registered to it, including itself prom_collector_registry_destroy(PROM_COLLECTOR_REGISTRY_DEFAULT); PROM_COLLECTOR_REGISTRY_DEFAULT = NULL; @@ -123,7 +127,6 @@ int promtest_gauge_teardown(void) { return 0; } - /** * @brief The entrypoint to a worker thread within the prom_gauge_test */ @@ -131,9 +134,9 @@ static void *promtest_gauge_handler(void *data) { for (int i = 0; i < 1000000; i++) { prom_gauge_inc(foo_gauge, NULL); } - int *retval = (int*) malloc(sizeof(int)); + int *retval = (int *)malloc(sizeof(int)); *retval = 0; - return (void*) retval; + return (void *)retval; } /** @@ -166,14 +169,14 @@ static int promtest_parse_gauge_output(const char *output, char **value) { if (samples == NULL) { TEST_FAIL_MESSAGE("failed to retrieve metrics from JSON_Object"); } - if (json_array_get_count(samples) < 1){ + if (json_array_get_count(samples) < 1) { TEST_FAIL_MESSAGE("No samples found"); } JSON_Object *sample = json_array_get_object(samples, 0); if (sample == NULL) { TEST_FAIL_MESSAGE("failed to get metric sample"); } - *value = (char *) json_object_get_string(sample, "value"); + *value = (char *)json_object_get_string(sample, "value"); break; } if (strlen(*value) == 0) { @@ -181,4 +184,3 @@ static int promtest_parse_gauge_output(const char *output, char **value) { } return 0; } - diff --git a/promtest/test/promtest_gauge.h b/promtest/test/promtest_gauge.h index 149fbbc..1abcc46 100644 --- a/promtest/test/promtest_gauge.h +++ b/promtest/test/promtest_gauge.h @@ -19,11 +19,11 @@ #ifndef PROMTEST_GAUGE_H #define PROMTEST_GAUGE_H -prom_gauge_t *foo_gauge; +extern prom_gauge_t *foo_gauge; int promtest_gauge_setup(void); int promtest_gauge_teardown(void); void promtest_gauge(void); -#endif // PROMTEST_GAUGE_H
\ No newline at end of file +#endif // PROMTEST_GAUGE_H
\ No newline at end of file diff --git a/promtest/test/promtest_helpers.c b/promtest/test/promtest_helpers.c index 01a0da2..e27d7ca 100644 --- a/promtest/test/promtest_helpers.c +++ b/promtest/test/promtest_helpers.c @@ -14,15 +14,18 @@ * limitations under the License. */ -#include <stdlib.h> +#include "promtest_helpers.h" + #include <stdio.h> +#include <stdlib.h> #include "prom.h" -#include "promtest_helpers.h" +struct MHD_Daemon *promtest_daemon; promtest_popen_buf_t *promtest_popen_buf_new(FILE *f) { - promtest_popen_buf_t *self = (promtest_popen_buf_t*) malloc(sizeof(promtest_popen_buf_t)); + promtest_popen_buf_t *self = + (promtest_popen_buf_t *)malloc(sizeof(promtest_popen_buf_t)); self->buf = malloc(32); self->size = 32; self->allocated = 32; @@ -31,9 +34,9 @@ promtest_popen_buf_t *promtest_popen_buf_new(FILE *f) { } int promtest_popen_buf_ensure_space(promtest_popen_buf_t *self) { - if (self->allocated >= self->size+1) return 0; - while (self->allocated < self->size+1) self->allocated <<= 1; - self->buf = (char *) prom_realloc(self->buf, self->allocated); + if (self->allocated >= self->size + 1) return 0; + while (self->allocated < self->size + 1) self->allocated <<= 1; + self->buf = (char *)prom_realloc(self->buf, self->allocated); return 0; } @@ -41,19 +44,16 @@ int promtest_popen_buf_destroy(promtest_popen_buf_t *self) { if (self == NULL) { return 0; } - free((void*) self->buf); + free((void *)self->buf); self->buf = NULL; - free((void*) self); + free((void *)self); self = NULL; return 0; } -int promtest_popen_buf_read(promtest_popen_buf_t* self) { - for ( - int current_char = fgetc(self->f), i = 0; - current_char != EOF; - current_char = fgetc(self->f), i++ - ) { +int promtest_popen_buf_read(promtest_popen_buf_t *self) { + for (int current_char = fgetc(self->f), i = 0; current_char != EOF; + current_char = fgetc(self->f), i++) { promtest_popen_buf_ensure_space(self); self->buf[i] = current_char; self->size++; diff --git a/promtest/test/promtest_helpers.h b/promtest/test/promtest_helpers.h index 4bdc6a2..b6cb2c3 100644 --- a/promtest/test/promtest_helpers.h +++ b/promtest/test/promtest_helpers.h @@ -21,7 +21,7 @@ #define PROMTEST_THREAD_POOL_SIZE 5 -struct MHD_Daemon *promtest_daemon; +extern struct MHD_Daemon *promtest_daemon; typedef struct promtest_popen_buf { char *buf; @@ -32,9 +32,7 @@ typedef struct promtest_popen_buf { promtest_popen_buf_t *promtest_popen_buf_new(FILE *f); int promtest_popen_buf_destroy(promtest_popen_buf_t *self); -int promtest_popen_buf_read(promtest_popen_buf_t* self); +int promtest_popen_buf_read(promtest_popen_buf_t *self); int promtest_popen_buf_ensure_space(promtest_popen_buf_t *self); - -#endif // PROMTEST_HELPERS_H - +#endif // PROMTEST_HELPERS_H |
