Apache HTTPD
testflock.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "testflock.h"
18#include "testutil.h"
19#include "apr_pools.h"
20#include "apr_thread_proc.h"
21#include "apr_file_io.h"
22#include "apr_file_info.h"
23#include "apr_general.h"
24#include "apr_strings.h"
25
26static int launch_reader(abts_case *tc)
27{
28 apr_proc_t proc = {0};
29 apr_procattr_t *procattr;
30 const char *args[2];
31 apr_status_t rv;
33 int exitcode;
34
35 rv = apr_procattr_create(&procattr, p);
36 APR_ASSERT_SUCCESS(tc, "Couldn't create procattr", rv);
37
40 APR_ASSERT_SUCCESS(tc, "Couldn't set io in procattr", rv);
41
43 APR_ASSERT_SUCCESS(tc, "Couldn't set copy environment", rv);
44
45 rv = apr_procattr_error_check_set(procattr, 1);
46 APR_ASSERT_SUCCESS(tc, "Couldn't set error check in procattr", rv);
47
48 args[0] = "tryread" EXTENSION;
49 args[1] = NULL;
50 rv = apr_proc_create(&proc, TESTBINPATH "tryread" EXTENSION, args, NULL, procattr, p);
51 APR_ASSERT_SUCCESS(tc, "Couldn't launch program", rv);
52
53 ABTS_ASSERT(tc, "wait for child process",
55
56 ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT);
57 return exitcode;
58}
59
60static void test_withlock(abts_case *tc, void *data)
61{
63 apr_status_t rv;
64 int code;
65
68 APR_ASSERT_SUCCESS(tc, "Could not create file.", rv);
70
72 APR_ASSERT_SUCCESS(tc, "Could not lock the file.", rv);
74
75 code = launch_reader(tc);
77
78 (void) apr_file_close(file);
79}
80
81static void test_withoutlock(abts_case *tc, void *data)
82{
83 int code;
84
85 code = launch_reader(tc);
87}
88
89static void remove_lockfile(abts_case *tc, void *data)
90{
91 APR_ASSERT_SUCCESS(tc, "Couldn't remove lock file.",
93}
94
96{
97 suite = ADD_SUITE(suite)
98
102
103 return suite;
104}
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_PTR_NOTNULL(a, b)
Definition abts.h:125
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
#define EXTENSION
Definition testutil.h:43
#define TESTBINPATH
Definition testutil.h:35
#define APR_ASSERT_SUCCESS(tc, ctxt, rv)
Definition testutil.h:58
APR File Information.
APR File I/O Handling.
APR Miscellaneous library routines.
APR memory allocation.
APR Strings library.
APR Thread and Process Library.
#define APR_CHILD_DONE
Definition apr_errno.h:446
apr_size_t size
int apr_status_t
Definition apr_errno.h:44
void * data
const char apr_file_t * file
#define APR_FLOCK_EXCLUSIVE
#define APR_FOPEN_WRITE
Definition apr_file_io.h:55
#define APR_FOPEN_CREATE
Definition apr_file_io.h:56
#define APR_OS_DEFAULT
apr_proc_t * proc
const char const char *const * args
#define APR_NO_PIPE
apr_exit_why_e
int * exitcode
@ APR_WAIT
@ APR_PROC_EXIT
@ APR_PROGRAM_ENV
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
apr_status_t apr_file_lock(apr_file_t *thefile, int type)
Definition flock.c:21
static void remove_lockfile(abts_case *tc, void *data)
Definition testflock.c:89
static void test_withlock(abts_case *tc, void *data)
Definition testflock.c:60
abts_suite * testflock(abts_suite *suite)
Definition testflock.c:95
static void test_withoutlock(abts_case *tc, void *data)
Definition testflock.c:81
static int launch_reader(abts_case *tc)
Definition testflock.c:26
#define TESTFILE
Definition testflock.h:20
#define SUCCESSFUL_READ
Definition testflock.h:23
#define FAILED_READ
Definition testflock.h:22