Changeset 4b54bd9 in mainline for uspace/lib/pcut/src/os


Ignore:
Timestamp:
2018-09-12T13:23:03Z (7 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3da0ee4
Parents:
275530a4
Message:

Update PCUT to latest revision

Location:
uspace/lib/pcut/src/os
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/src/os/generic.c

    r275530a4 r4b54bd9  
    3131 * Platform-dependent test execution function when system() is available.
    3232 */
    33 
     33#pragma warning(push, 0)
    3434#include <stdlib.h>
    3535#include <stdio.h>
     
    3838#include <assert.h>
    3939#include <string.h>
     40#pragma warning(pop)
     41
    4042#include "../internal.h"
    4143
     
    5557
    5658#define FORMAT_COMMAND(buffer, buffer_size, self_path, test_id, temp_file) \
    57         snprintf(buffer, buffer_size, "\"\"%s\" -t%d >%s\"", self_path, test_id, temp_file)
     59        pcut_snprintf(buffer, buffer_size, "\"\"%s\" -t%d >%s\"", self_path, test_id, temp_file)
    5860#define FORMAT_TEMP_FILENAME(buffer, buffer_size) \
    59         snprintf(buffer, buffer_size, "pcut_%d.tmp", _getpid())
     61        pcut_snprintf(buffer, buffer_size, "pcut_%d.tmp", _getpid())
    6062
    6163#elif defined(__unix)
     
    6365
    6466#define FORMAT_COMMAND(buffer, buffer_size, self_path, test_id, temp_file) \
    65         snprintf(buffer, buffer_size, "%s -t%d &>%s", self_path, test_id, temp_file)
     67        pcut_snprintf(buffer, buffer_size, "%s -t%d &>%s", self_path, test_id, temp_file)
    6668#define FORMAT_TEMP_FILENAME(buffer, buffer_size) \
    67         snprintf(buffer, buffer_size, "pcut_%d.tmp", getpid())
     69        pcut_snprintf(buffer, buffer_size, "pcut_%d.tmp", getpid())
    6870
    6971#else
     
    8183 * @param test Test that is about to start.
    8284 */
    83 static void before_test_start(pcut_item_t *test)
    84 {
     85static void before_test_start(pcut_item_t *test) {
    8586        pcut_report_test_start(test);
    8687
     
    9495 * @return Test outcome code.
    9596 */
    96 static int convert_wait_status_to_outcome(int status)
    97 {
     97static int convert_wait_status_to_outcome(int status) {
    9898        if (status < 0) {
    9999                return PCUT_OUTCOME_INTERNAL_ERROR;
     
    110110 * @param test Test to be run.
    111111 */
    112 int pcut_run_test_forking(const char *self_path, pcut_item_t *test)
    113 {
     112int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    114113        int rc, outcome;
    115114        FILE *tempfile;
     
    121120        FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1);
    122121        FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1,
    123             self_path, (test)->id, tempfile_name);
    124 
     122                self_path, (test)->id, tempfile_name);
     123       
    125124        PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().",
    126             command, tempfile_name);
     125                command, tempfile_name);
    127126
    128127        rc = system(command);
     
    147146}
    148147
    149 void pcut_hook_before_test(pcut_item_t *test)
    150 {
     148void pcut_hook_before_test(pcut_item_t *test) {
    151149        PCUT_UNUSED(test);
    152150
  • uspace/lib/pcut/src/os/helenos.c

    r275530a4 r4b54bd9  
    4646/* String functions. */
    4747
    48 int pcut_str_equals(const char *a, const char *b)
    49 {
     48int pcut_str_equals(const char *a, const char *b) {
    5049        return str_cmp(a, b) == 0;
    5150}
    5251
    5352
    54 int pcut_str_start_equals(const char *a, const char *b, int len)
    55 {
     53int pcut_str_start_equals(const char *a, const char *b, int len) {
    5654        return str_lcmp(a, b, len) == 0;
    5755}
    5856
    59 int pcut_str_size(const char *s)
    60 {
     57int pcut_str_size(const char *s) {
    6158        return str_size(s);
    6259}
    6360
    64 int pcut_str_to_int(const char *s)
    65 {
     61int pcut_str_to_int(const char *s) {
    6662        int result = strtol(s, NULL, 10);
    6763        return result;
    6864}
    6965
    70 char *pcut_str_find_char(const char *haystack, const char needle)
    71 {
     66char *pcut_str_find_char(const char *haystack, const char needle) {
    7267        return str_chr(haystack, needle);
    7368}
    7469
    75 void pcut_str_error(errno_t error, char *buffer, int size)
    76 {
     70void pcut_str_error(int error, char *buffer, int size) {
    7771        const char *str = str_error(error);
    7872        if (str == NULL) {
     
    107101 * @param test Test that is about to be run.
    108102 */
    109 static void before_test_start(pcut_item_t *test)
    110 {
     103static void before_test_start(pcut_item_t *test) {
    111104        pcut_report_test_start(test);
    112105
     
    116109
    117110/** Mutex guard for forced_termination_cv. */
    118 static fibril_mutex_t forced_termination_mutex =
    119     FIBRIL_MUTEX_INITIALIZER(forced_termination_mutex);
     111static fibril_mutex_t forced_termination_mutex
     112        = FIBRIL_MUTEX_INITIALIZER(forced_termination_mutex);
    120113
    121114/** Condition-variable for checking whether test timed-out. */
    122 static fibril_condvar_t forced_termination_cv =
    123     FIBRIL_CONDVAR_INITIALIZER(forced_termination_cv);
     115static fibril_condvar_t forced_termination_cv
     116        = FIBRIL_CONDVAR_INITIALIZER(forced_termination_cv);
    124117
    125118/** Spawned task id. */
     
    137130 * @return EOK Always.
    138131 */
    139 static errno_t test_timeout_handler_fibril(void *arg)
    140 {
     132static int test_timeout_handler_fibril(void *arg) {
    141133        pcut_item_t *test = arg;
    142134        int timeout_sec = pcut_get_test_timeout(test);
     
    148140        }
    149141        errno_t rc = fibril_condvar_wait_timeout(&forced_termination_cv,
    150             &forced_termination_mutex, timeout_us);
     142                &forced_termination_mutex, timeout_us);
    151143        if (rc == ETIMEOUT) {
    152144                task_kill(test_task_id);
     
    162154 * @param test Test to be run.
    163155 */
    164 int pcut_run_test_forking(const char *self_path, pcut_item_t *test)
    165 {
     156int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    166157        before_test_start(test);
    167158
     
    235226}
    236227
    237 void pcut_hook_before_test(pcut_item_t *test)
    238 {
     228void pcut_hook_before_test(pcut_item_t *test) {
    239229        PCUT_UNUSED(test);
    240230
  • uspace/lib/pcut/src/os/stdc.c

    r275530a4 r4b54bd9  
    3232 */
    3333
     34#pragma warning(push, 0)
    3435#include <string.h>
     36#pragma warning(pop)
     37
    3538#include "../internal.h"
    3639
    37 int pcut_str_equals(const char *a, const char *b)
    38 {
     40int pcut_str_equals(const char *a, const char *b) {
    3941        return strcmp(a, b) == 0;
    4042}
    4143
    42 int pcut_str_start_equals(const char *a, const char *b, int len)
    43 {
     44int pcut_str_start_equals(const char *a, const char *b, int len) {
    4445        return strncmp(a, b, len) == 0;
    4546}
    4647
    47 int pcut_str_size(const char *s)
    48 {
     48int pcut_str_size(const char *s) {
    4949        return strlen(s);
    5050}
    5151
    52 int pcut_str_to_int(const char *s)
    53 {
     52int pcut_str_to_int(const char *s) {
    5453        return atoi(s);
    5554}
    5655
    57 char *pcut_str_find_char(const char *haystack, const char needle)
    58 {
     56char *pcut_str_find_char(const char *haystack, const char needle) {
    5957        return strchr(haystack, needle);
    6058}
    6159
    62 void pcut_str_error(int error, char *buffer, int size)
    63 {
     60void pcut_str_error(int error, char *buffer, int size) {
    6461        const char *str = strerror(error);
    6562        if (str == NULL) {
  • uspace/lib/pcut/src/os/unix.c

    r275530a4 r4b54bd9  
    6464 * @param test Test that is about to be run.
    6565 */
    66 static void before_test_start(pcut_item_t *test)
    67 {
     66static void before_test_start(pcut_item_t *test) {
    6867        pcut_report_test_start(test);
    6968
     
    7978 * @param sig Signal number.
    8079 */
    81 static void kill_child_on_alarm(int sig)
    82 {
     80static void kill_child_on_alarm(int sig) {
    8381        PCUT_UNUSED(sig);
    8482        kill(child_pid, SIGKILL);
     
    9694 * @return Number of actually read bytes.
    9795 */
    98 static size_t read_all(int fd, char *buffer, size_t buffer_size)
    99 {
     96static size_t read_all(int fd, char *buffer, size_t buffer_size) {
    10097        ssize_t actually_read;
    10198        char *buffer_start = buffer;
     
    124121 * @return Test outcome code.
    125122 */
    126 static int convert_wait_status_to_outcome(int status)
    127 {
     123static int convert_wait_status_to_outcome(int status) {
    128124        if (WIFEXITED(status)) {
    129125                if (WEXITSTATUS(status) != 0) {
     
    146142 * @param test Test to be run.
    147143 */
    148 int pcut_run_test_forking(const char *self_path, pcut_item_t *test)
    149 {
     144int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    150145        int link_stdout[2], link_stderr[2];
    151146        int rc, status, outcome;
     
    159154        rc = pipe(link_stdout);
    160155        if (rc == -1) {
    161                 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    162                     "pipe() failed: %s.", strerror(rc));
     156                pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
     157                                "pipe() failed: %s.", strerror(rc));
    163158                pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL);
    164159                return PCUT_OUTCOME_INTERNAL_ERROR;
     
    166161        rc = pipe(link_stderr);
    167162        if (rc == -1) {
    168                 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    169                     "pipe() failed: %s.", strerror(rc));
     163                pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
     164                                "pipe() failed: %s.", strerror(rc));
    170165                pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL);
    171166                return PCUT_OUTCOME_INTERNAL_ERROR;
     
    174169        child_pid = fork();
    175170        if (child_pid == (pid_t)-1) {
    176                 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    177                     "fork() failed: %s.", strerror(rc));
     171                pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
     172                        "fork() failed: %s.", strerror(rc));
    178173                outcome = PCUT_OUTCOME_INTERNAL_ERROR;
    179174                goto leave_close_pipes;
     
    220215}
    221216
    222 void pcut_hook_before_test(pcut_item_t *test)
    223 {
     217void pcut_hook_before_test(pcut_item_t *test) {
    224218        PCUT_UNUSED(test);
    225219
  • uspace/lib/pcut/src/os/windows.c

    r275530a4 r4b54bd9  
    3939#include "../internal.h"
    4040
     41#pragma warning(push, 0)
    4142#include <windows.h>
    4243#include <tchar.h>
    4344#include <stdio.h>
    4445#include <strsafe.h>
     46#pragma warning(pop)
     47
    4548
    4649
     
    6164 * @param test Test that is about to be run.
    6265 */
    63 static void before_test_start(pcut_item_t *test)
    64 {
     66static void before_test_start(pcut_item_t *test) {
    6567        pcut_report_test_start(test);
    6668
     
    7476 * @param failed_function_name Name of the failed function.
    7577 */
    76 static void report_func_fail(pcut_item_t *test, const char *failed_function_name)
    77 {
     78static void report_func_fail(pcut_item_t *test, const char *failed_function_name) {
    7879        /* TODO: get error description. */
    79         sprintf_s(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    80             "%s failed: %s.", failed_function_name, "unknown reason");
    81         pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);
     80        pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
     81                "%s failed: %s.", failed_function_name, "unknown reason");
     82        pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL);
    8283}
    8384
     
    9394 * @return Number of actually read bytes.
    9495 */
    95 static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size)
    96 {
     96static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size) {
    9797        DWORD actually_read;
    9898        char *buffer_start = buffer;
     
    128128};
    129129
    130 static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr)
    131 {
     130static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr) {
    132131        size_t stderr_size = 0;
    133132        struct test_output_data *test_output_data = (struct test_output_data *) test_output_data_ptr;
    134133
    135134        stderr_size = read_all(test_output_data->pipe_stderr,
    136             test_output_data->output_buffer,
    137             test_output_data->output_buffer_size - 1);
     135                test_output_data->output_buffer,
     136                test_output_data->output_buffer_size - 1);
    138137        read_all(test_output_data->pipe_stdout,
    139             test_output_data->output_buffer,
    140             test_output_data->output_buffer_size - 1 - stderr_size);
     138                test_output_data->output_buffer,
     139                test_output_data->output_buffer_size - 1 - stderr_size);
    141140
    142141        return 0;
     
    148147 * @param test Test to be run.
    149148 */
    150 int pcut_run_test_forking(const char *self_path, pcut_item_t *test)
    151 {
     149int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    152150        /* TODO: clean-up if something goes wrong "in the middle" */
    153151        BOOL okay = FALSE;
     
    220218
    221219        /* Format the command line. */
    222         sprintf_s(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1,
    223             "\"%s\" -t%d", self_path, test->id);
     220        pcut_snprintf(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1,
     221                "\"%s\" -t%d", self_path, test->id);
    224222
    225223        /* Run the process. */
    226224        okay = CreateProcess(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL,
    227             &start_info, &process_info);
     225                &start_info, &process_info);
    228226
    229227        if (!okay) {
     
    267265
    268266        test_output_thread_reader = CreateThread(NULL, 0,
    269             read_test_output_on_background, &test_output_data,
    270             0, NULL);
     267                read_test_output_on_background, &test_output_data,
     268                0, NULL);
    271269
    272270        if (test_output_thread_reader == NULL) {
     
    286284                if (!okay) {
    287285                        report_func_fail(test, "TerminateProcess(/* PROCESS_INFORMATION.hProcess */)");
    288                         return PCUT_ERROR_INTERNAL_FAILURE;
     286                        return PCUT_OUTCOME_INTERNAL_ERROR;
    289287                }
    290288                rc = WaitForSingleObject(process_info.hProcess, INFINITE);
     
    314312        if (rc != WAIT_OBJECT_0) {
    315313                report_func_fail(test, "WaitForSingleObject(/* stdout reader thread */)");
    316                 return PCUT_ERROR_INTERNAL_FAILURE;
     314                return PCUT_OUTCOME_INTERNAL_ERROR;
    317315        }
    318316
     
    322320}
    323321
    324 void pcut_hook_before_test(pcut_item_t *test)
    325 {
     322void pcut_hook_before_test(pcut_item_t *test) {
    326323        PCUT_UNUSED(test);
    327324
Note: See TracChangeset for help on using the changeset viewer.