Skip to content

Commit 3e4eb7c

Browse files
author
Justin Boswell
authored
Added unit tests for TLS negotiation failure and download of a medium… (#37)
* Added unit tests for TLS negotiation failure and download of a medium-size file * Use RelWithDebInfo so test failures have meaningful callstacks * pinned versions of aws-c-common and aws-c-io for CI
1 parent 095acca commit 3e4eb7c

File tree

6 files changed

+356
-7
lines changed

6 files changed

+356
-7
lines changed

codebuild/common-posix.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
#!/bin/bash
22

33
set -e
4+
set -x
45

56
echo "Using CC=$CC CXX=$CXX"
67

78
BUILD_PATH=/tmp/builds
89
mkdir -p $BUILD_PATH
910
INSTALL_PATH=$BUILD_PATH/install
1011
mkdir -p $INSTALL_PATH
11-
CMAKE_ARGS="-DCMAKE_PREFIX_PATH=$INSTALL_PATH -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DENABLE_SANITIZERS=ON $@"
12+
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=$INSTALL_PATH -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DENABLE_SANITIZERS=ON $@"
13+
14+
# pushd $BUILD_PATH
15+
# curl -LO https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2
16+
# tar xvjf valgrind-*.tar.bz2
17+
# cd valgrind-3.15.0
18+
# ./configure
19+
# make -j && sudo make install
20+
# sudo apt-get install -y libc6-dbg
21+
# popd
1222

1323
# install_library <git_repo> [<commit>]
1424
function install_library {
@@ -31,14 +41,15 @@ if [ "$TRAVIS_OS_NAME" != "osx" ]; then
3141
sudo apt-get install libssl-dev -y
3242
install_library s2n 7c9069618e68214802ac7fbf45705d5f8b53135f
3343
fi
34-
install_library aws-c-common
35-
install_library aws-c-io
44+
install_library aws-c-common v0.3.7
45+
install_library aws-c-io v0.3.5
3646

3747
mkdir -p build
3848
pushd build
3949
cmake $CMAKE_ARGS ../
4050
cmake --build . --target install
4151

52+
#valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all `pwd`/tests/aws-c-http-tests tls_negotiation_timeout
4253
LSAN_OPTIONS=verbosity=1:log_threads=1 ctest --output-on-failure
4354
popd
4455
python3 integration-testing/http_client_test.py $INSTALL_PATH/bin/elasticurl

source/connection.c

+5
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ static void s_client_bootstrap_on_channel_setup(
412412
goto error;
413413
}
414414

415+
if (!channel) {
416+
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Client connection did not produce a channel");
417+
goto error;
418+
}
419+
415420
AWS_LOGF_TRACE(AWS_LS_HTTP_CONNECTION, "static: Socket connected, creating client connection object.");
416421

417422
struct aws_http_connection *connection = s_connection_new(channel, false, options->is_using_tls, options);

source/connection_h1.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ struct aws_http_stream *s_new_client_request_stream(const struct aws_http_reques
445445

446446
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\r');
447447
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\n');
448-
448+
(void)wrote_all;
449449
assert(wrote_all);
450450

451451
/* Insert new stream into pending list, and schedule outgoing_stream_task if it's not already running. */
@@ -543,6 +543,11 @@ static void s_update_window_task(struct aws_channel_task *channel_task, void *ar
543543
AWS_FATAL_ASSERT(!err);
544544

545545
size_t window_update_size = connection->synced_data.window_update_size;
546+
AWS_LOGF_TRACE(
547+
AWS_LS_HTTP_CONNECTION,
548+
"id=%p: Zeroing window update size, was %zu",
549+
(void *)&connection->base,
550+
window_update_size);
546551
connection->synced_data.window_update_size = 0;
547552

548553
err = aws_mutex_unlock(&connection->synced_data.lock);
@@ -573,8 +578,9 @@ static void s_stream_update_window(struct aws_http_stream *stream, size_t increm
573578
int err = aws_mutex_lock(&connection->synced_data.lock);
574579
AWS_FATAL_ASSERT(!err);
575580

576-
bool should_schedule_task = connection->synced_data.window_update_size == 0;
577-
581+
/* if this is not volatile, gcc-4x will load window_update_size's address into a register
582+
* and then read it as should_schedule_task down below, which will invert its meaning */
583+
volatile bool should_schedule_task = (connection->synced_data.window_update_size == 0);
578584
connection->synced_data.window_update_size =
579585
aws_add_size_saturating(connection->synced_data.window_update_size, increment_size);
580586

tests/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ add_test_case(h1_client_close_from_incoming_body_callback_stops_decoder)
5454
add_test_case(h1_client_close_from_stream_complete_callback_stops_decoder)
5555
add_test_case(h1_client_close_from_off_thread_makes_not_open)
5656
add_test_case(h1_client_close_from_on_thread_makes_not_open)
57+
add_test_case(tls_negotiation_timeout)
58+
add_test_case(tls_download_medium_file)
5759
add_test_case(websocket_decoder_sanity_check)
5860
add_test_case(websocket_decoder_simplest_frame)
5961
add_test_case(websocket_decoder_rsv)

tests/test_h1_client.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,9 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
11501150
"Call Momo";
11511151
ASSERT_SUCCESS(s_send_response_str(&tester, response_str));
11521152

1153+
/* drain the task queue, in case there's an update window task in there from the headers */
1154+
testing_channel_execute_queued_tasks(&tester.testing_channel);
1155+
11531156
/* check result */
11541157
if (!on_thread) {
11551158
testing_channel_set_is_on_users_thread(&tester.testing_channel, false);
@@ -1161,9 +1164,10 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
11611164
testing_channel_set_is_on_users_thread(&tester.testing_channel, true);
11621165
testing_channel_execute_queued_tasks(&tester.testing_channel);
11631166
}
1167+
testing_channel_execute_queued_tasks(&tester.testing_channel);
11641168

11651169
size_t window_update = testing_channel_last_window_update(&tester.testing_channel);
1166-
ASSERT_TRUE(window_update == 9);
1170+
ASSERT_INT_EQUALS(9, window_update);
11671171

11681172
/* clean up */
11691173
ASSERT_SUCCESS(s_response_tester_clean_up(&response));

0 commit comments

Comments
 (0)