Skip to content

Commit

Permalink
Initial work on a YouTube test (#17).
Browse files Browse the repository at this point in the history
Using headless Chromium to fetch a YouTube video and measure how well it
performs. Things to note:

 * Conflicts between libssl and libboringssl mean youtube.so needs to be
   loaded into it's own link-map namespace. This appears to make all memory
   allocated in the run callback off limits to us outside of the callback,
   so have resorted to using shared memory to get the results out.

 * Chromium forks the original process multiple times as part of its normal
   operation, which (when running through the amplet2 scheduler) would
   attempt to rerun amplet2 so we replace ourselves with the standalone
   binary while running.
  • Loading branch information
brendonj committed Mar 16, 2018
1 parent 8731a2f commit 4643b71
Show file tree
Hide file tree
Showing 12 changed files with 1,391 additions and 5 deletions.
39 changes: 37 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
AC_PREREQ([2.67])
AC_INIT([amplet2], [0.8.1], [[email protected]])
#AC_CONFIG_SRCDIR([src/measured/measured.c])
AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_HEADERS([config.h])

AC_CONFIG_MACRO_DIR([m4])
Expand All @@ -13,6 +13,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AC_PROG_LIBTOOL

Expand Down Expand Up @@ -302,6 +303,37 @@ AC_ARG_ENABLE(udpstream,
# using AM_CONDITIONAL propagates this value through to all Makefile.am files
AM_CONDITIONAL(WANT_UDPSTREAM_TEST, [test x"$want_udpstream_test" = xtrue])

AC_ARG_ENABLE(youtube,
AC_HELP_STRING([--enable-youtube],
[Enable the youtube test (default: no)]),
[case "${enableval}" in
true) ;&
yes) want_youtube_test=true ;;
false) ;&
no) want_youtube_test=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-youtube) ;;
esac],
[want_youtube_test=false])

CHROMIUM_INCLUDE_DIR=""
AC_ARG_WITH(chromium-build,
AC_HELP_STRING([--with-chromium-build=DIR],
[Specify the base location of the built chromium libraries]),
[CHROMIUM_BUILD_DIR="${withval}" CHROMIUM_INCLUDE_DIR="-I${withval}/gen" want_youtube_test=true])
AC_SUBST(CHROMIUM_BUILD_DIR)

AC_ARG_WITH(chromium-includes,
AC_HELP_STRING([--with-chromium-includes=DIR],
[Specify the location of the chromium headers]),
[CHROMIUM_INCLUDE_DIR+=" -I${withval}" want_youtube_test=true])
AC_SUBST(CHROMIUM_INCLUDE_DIR)


# using AM_CONDITIONAL propagates this value through to all Makefile.am files
AM_CONDITIONAL(WANT_YOUTUBE_TEST, [test x"$want_youtube_test" = xtrue])



# Set default CFLAGS including the AMP_CONFIG_DIR and AMP_TEST_DIR
AC_SUBST([AM_CFLAGS], ["-rdynamic -g -Wall -W -D_GNU_SOURCE -DAMP_CONFIG_DIR=\\\"\$(sysconfdir)/\$(PACKAGE)\\\" -DAMP_TEST_DIRECTORY=\\\"\$(libdir)/\$(PACKAGE)/tests\\\" -DAMP_LOG_DIR=\\\"\$(localstatedir)/log/\\\""])

Expand Down Expand Up @@ -330,7 +362,9 @@ AC_CONFIG_FILES([Makefile
src/tests/throughput/test/Makefile
src/tests/remoteskeleton/Makefile
src/tests/udpstream/Makefile
src/tests/udpstream/test/Makefile])
src/tests/udpstream/test/Makefile
src/tests/youtube/Makefile])
#src/tests/youtube/test/Makefile])
AC_OUTPUT

reportopt() {
Expand All @@ -352,3 +386,4 @@ reportopt "Compiled with http test support" $want_http_test
reportopt "Compiled with throughput test support" $want_throughput_test
reportopt "Compiled with tcpping test support" $want_tcpping_test
reportopt "Compiled with udpstream test support" $want_udpstream_test
reportopt "Compiled with youtube test support" $want_youtube_test
22 changes: 19 additions & 3 deletions src/common/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ int register_tests(char *location) {
location, glob_buf.gl_pathc);

for ( i=0; i<glob_buf.gl_pathc; i++ ) {
hdl = dlopen(glob_buf.gl_pathv[i], RTLD_LAZY);
/*
* XXX temporarily load the new youtube test into its own link-map
* namespace to avoid conflicts with symbols in libboringssl and
* libssl. There should be more isolation between tests so that
* library symbols don't conflict.
*/
if ( strcmp(basename(glob_buf.gl_pathv[i]), "youtube.so") == 0 ) {
hdl = dlmopen(LM_ID_NEWLM, glob_buf.gl_pathv[i], RTLD_LAZY);
} else {
hdl = dlopen(glob_buf.gl_pathv[i], RTLD_LAZY);
}

if ( !hdl ) {
Log(LOG_WARNING, "Failed to dlopen() file %s",
Expand Down Expand Up @@ -139,8 +149,14 @@ void unregister_tests() {
for ( i=0; i<AMP_TEST_LAST; i++) {
if ( amp_tests[i] != NULL ) {
dlclose(amp_tests[i]->dlhandle);
free(amp_tests[i]->name);
free(amp_tests[i]);
/*
* XXX temporary: youtube test allocations are in another
* link-map namespace, so we shouldn't really touch them.
*/
if ( i != AMP_TEST_YOUTUBE ) {
free(amp_tests[i]->name);
free(amp_tests[i]);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/common/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef enum {
AMP_TEST_TCPPING,
AMP_TEST_REMOTE_SKELETON,
AMP_TEST_UDPSTREAM,
AMP_TEST_YOUTUBE,
AMP_TEST_LAST,
} test_type_t;

Expand Down
61 changes: 61 additions & 0 deletions src/measured/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include <sys/types.h>
#include <ifaddrs.h>
#include <libwandevent.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "config.h"
#include "schedule.h"
Expand Down Expand Up @@ -325,6 +328,59 @@ void run_test(const test_schedule_item_t * const item, BIO *ctrl) {
result = test->run_callback(argc, argv,
item->dest_count + total_resolve_count, destinations);

/*
* XXX temporary: convert the youtube test result into a normal
* result structure by reading from shared memory. We can't use
* memory allocated inside the test as it is in a different link-map
* namespace.
*/
if ( test->id == AMP_TEST_YOUTUBE ) {
char *filename;
int fd;

/* the filename is /amp-testtype-pid */
if ( asprintf(&filename, "/amp-youtube-%d", getpid()) < 0 ) {
Log(LOG_WARNING, "Failed to create filename");
return;
}
if ( (fd = shm_open(filename, O_RDONLY, 0)) < 0 ) {
free(filename);
Log(LOG_WARNING, "Failed to open shared file");
return;
}
free(filename);
result = calloc(1, sizeof(amp_test_result_t));
lseek(fd, 0, SEEK_SET);
if ( read(fd, &result->timestamp, sizeof(result->timestamp)) !=
sizeof(result->timestamp) ) {
free(result);
close(fd);
Log(LOG_WARNING, "Failed to read timestamp");
return;
}
if ( read(fd, &result->len, sizeof(result->len)) !=
sizeof(result->len) ) {
free(result);
close(fd);
Log(LOG_WARNING, "Failed to read length");
return;
}
if ( result->len > 4096 ) {
Log(LOG_WARNING, "Ignoring too-large youtube test result");
free(result);
close(fd);
return;
}
result->data = malloc(result->len);
if ( read(fd, result->data, result->len) != result->len ) {
free(result);
close(fd);
Log(LOG_WARNING, "Failed to read data");
return;
}
close(fd);
}

if ( result ) {
/* report the results to the appropriate location */
if ( ctrl ) {
Expand Down Expand Up @@ -381,6 +437,11 @@ void run_test(const test_schedule_item_t * const item, BIO *ctrl) {
free_duped_environ();

/* done running the test, exit */
if ( test->id == AMP_TEST_YOUTUBE ) {
/* XXX something is registering atexit() functions that crash? */
_exit(0);
}

exit(0);
}

Expand Down
4 changes: 4 additions & 0 deletions src/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ endif
if WANT_UDPSTREAM_TEST
SUBDIRS+=udpstream
endif

if WANT_YOUTUBE_TEST
SUBDIRS+=youtube
endif
44 changes: 44 additions & 0 deletions src/tests/youtube/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
EXTRA_DIST=*.h youtube.proto yt.html
#SUBDIRS= . test
SUBDIRS= .
BUILT_SOURCES=youtube.pb-c.c
CLEANFILES=youtube.pb-c.c youtube.pb-c.h

CHROMIUM_INTERFACES_DIR=@CHROMIUM_BUILD_DIR@/obj/services/service_manager/public/interfaces/interfaces
CHROMIUM_SHARED_INTERFACES_DIR=@CHROMIUM_BUILD_DIR@/obj/services/service_manager/public/interfaces/interfaces_shared_cpp_sources
CHROMIUM_TYPES_DIR=@CHROMIUM_BUILD_DIR@/obj/mojo/common/common_custom_types
CHROMIUM_SHARED_TYPES_DIR=@CHROMIUM_BUILD_DIR@/obj/mojo/common/common_custom_types_shared_cpp_sources

CHROMIUM_OBJECTS=@CHROMIUM_BUILD_DIR@/obj/components/crash/content/browser/browser/crash_handler_host_linux.o @CHROMIUM_BUILD_DIR@/obj/components/crash/content/app/app_non_mac_win/breakpad_linux.o @CHROMIUM_BUILD_DIR@/obj/content/public/common/service_names/service_names.mojom.o @CHROMIUM_BUILD_DIR@/obj/content/public/common/service_names_shared_cpp_sources/service_names.mojom-shared.o ${CHROMIUM_INTERFACES_DIR}/connector.mojom.o ${CHROMIUM_INTERFACES_DIR}/interface_provider.mojom.o ${CHROMIUM_INTERFACES_DIR}/interface_provider_spec.mojom.o ${CHROMIUM_INTERFACES_DIR}/resolver.mojom.o ${CHROMIUM_INTERFACES_DIR}/service.mojom.o ${CHROMIUM_INTERFACES_DIR}/service_control.mojom.o ${CHROMIUM_INTERFACES_DIR}/service_factory.mojom.o ${CHROMIUM_INTERFACES_DIR}/service_manager.mojom.o ${CHROMIUM_SHARED_INTERFACES_DIR}/connector.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/interface_provider.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/interface_provider_spec.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/resolver.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/service.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/service_control.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/service_factory.mojom-shared.o ${CHROMIUM_SHARED_INTERFACES_DIR}/service_manager.mojom-shared.o @CHROMIUM_BUILD_DIR@/obj/services/service_manager/public/interfaces/constants_shared_cpp_sources/constants.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/file.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/file_path.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/string16.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/text_direction.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/time.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/unguessable_token.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/values.mojom-shared.o ${CHROMIUM_SHARED_TYPES_DIR}/version.mojom-shared.o @CHROMIUM_BUILD_DIR@/obj/services/service_manager/public/interfaces/constants/constants.mojom.o ${CHROMIUM_TYPES_DIR}/file.mojom.o ${CHROMIUM_TYPES_DIR}/file_path.mojom.o ${CHROMIUM_TYPES_DIR}/string16.mojom.o ${CHROMIUM_TYPES_DIR}/text_direction.mojom.o ${CHROMIUM_TYPES_DIR}/time.mojom.o ${CHROMIUM_TYPES_DIR}/unguessable_token.mojom.o ${CHROMIUM_TYPES_DIR}/values.mojom.o ${CHROMIUM_TYPES_DIR}/version.mojom.o ${CHROMIUM_TYPES_DIR}/values_struct_traits.o @CHROMIUM_BUILD_DIR@/obj/mojo/common/struct_traits/common_custom_types_struct_traits.o @CHROMIUM_BUILD_DIR@/obj/headless/libheadless_shell_lib.a @CHROMIUM_BUILD_DIR@/obj/headless/libheadless_lib.a @CHROMIUM_BUILD_DIR@/obj/breakpad/libclient.a @CHROMIUM_BUILD_DIR@/obj/components/crash/content/app/libapp.a @CHROMIUM_BUILD_DIR@/obj/components/crash/content/app/lib.a @CHROMIUM_BUILD_DIR@/obj/base/libbase_static.a @CHROMIUM_BUILD_DIR@/obj/components/crash/core/common/libcrash_keys.a @CHROMIUM_BUILD_DIR@/obj/components/security_state/content/libcontent.a @CHROMIUM_BUILD_DIR@/obj/components/security_state/core/libcore.a @CHROMIUM_BUILD_DIR@/obj/services/service_manager/public/cpp/libsources.a

CHROMIUM_LIBS=-lbase,-lipc,-lbindings,-lmojo_public_system_cpp,-lmojo_public_system,-lcontent,-lgpu,-lgles2_utils,-lgfx,-lskia,-lgeometry,-licui18n,-licuuc,-lrange,-lgl_wrapper,-lplatform,-lgl_init,-lui_base,-lui_data_pack,-levents_base,-lurl,-lbase_i18n,-lnet,-lprotobuf_lite,-lcrcrypto,-lboringssl,-lmedia,-lshared_memory_support,-lmojo_common_lib,-lgfx_ipc,-lgfx_ipc_geometry,-lgfx_ipc_skia,-lcapture_base,-lgfx_ipc_color,-lcc,-lui_base_ime,-ldisplay,-ldisplay_types,-lcapture_lib,-lcc_ipc,-lcc_surfaces,-laccessibility,-lsurface,-lurl_ipc,-lmojo_system_impl,-lstorage_common,-lstorage_browser,-lcompositor,-ldevices,-laura,-lozone,-lozone_base,-ldisplay_util,-levents,-lgl,-lppapi_host,-lppapi_proxy,-lppapi_shared,-lblink_platform,-lblink_web,-lblink_core,-lblink_modules,-lseccomp_bpf,-lsql,-lv8,-lv8_libbase,-lv8_libplatform,-lchromium_sqlite3,-lgesture_detection,-lwtf,-ltracing,-ldiscardable_memory_client,-lstartup_tracing,-lgles2_implementation,-lmedia_gpu,-lmidi,-lsandbox_services,-lsuid_sandbox_client,-levents_ipc,-lshell_dialogs,-lnative_theme,-lgin,-ldisplay_compositor,-lcc_animation,-lcc_paint,-ldiscardable_memory_service,-lprefs,-ldevice_battery,-ldevice_gamepad,-lgeneric_sensor,-lcpp,-lgeolocation,-lpower_save_blocker,-lsensors,-ldevice_vibration,-ldevice_vr,-lsnapshot,-lui_touch_selection,-laura_extra,-lcc_blink,-ldevice_event_log,-lmedia_blink,-ljs,-lmojo_ime_lib,-lstub_window,-lffmpeg,-levents_ozone_layout,-lgl_in_process_context,-ldiscardable_memory_common,-lbluetooth

testdir=$(libdir)/$(PACKAGE)/tests
bin_PROGRAMS=amp-youtube
amp_youtube_SOURCES=../testmain.c
amp_youtube_CPPFLAGS=-I../../common/
amp_youtube_LDADD=youtube.la
amp_youtube_LDFLAGS=-L@CHROMIUM_BUILD_DIR@ -Wl,--no-as-needed -L../../common/ ${CHROMIUM_OBJECTS} -Wl,--as-needed -Wl,--start-group,${CHROMIUM_LIBS} -Wl,--end-group -Wl,--no-as-needed -ldl -lrt -lnss3 -lnssutil3 -lsmime3 -lplds4 -lplc4 -lnspr4 -lpthread -lprotobuf-c -lamp -lwandevent -lunbound -lstdc++

test_LTLIBRARIES=youtube.la
youtube_la_SOURCES=youtube.c chromium.cc
nodist_youtube_la_SOURCES=youtube.pb-c.c
youtube_la_CPPFLAGS=@CHROMIUM_INCLUDE_DIR@ -I../ -I../../common/ -fPIC -std=c++11 -DV8_DEPRECATION_WARNINGS -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -DDISABLE_NACL -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -DENABLE_MEDIA_ROUTER=1 -DFIELDTRIAL_TESTING_ENABLED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DCOMPONENT_BUILD -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DHEADLESS_IMPLEMENTATION -DHEADLESS_USE_EMBEDDED_RESOURCES -DUSE_EGL -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC -DSK_IGNORE_DW_GRAY_FIX -DSK_IGNORE_DIRECTWRITE_GASP_FIX -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 -DMESA_EGL_NO_X11_HEADERS -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -DHAVE_PTHREAD -DPROTOBUF_USE_DLLS -DBORINGSSL_SHARED_LIBRARY -DUSING_V8_SHARED -DAMP_EXTRA_DIRECTORY=\"\$(libdir)/\$(PACKAGE)/extra\"
#youtube_la_LIBADD=libstatics.la
#youtube_la_LDFLAGS=-L@CHROMIUM_BUILD_DIR@ -module -avoid-version -L../../common/ ${CHROMIUM_OBJECTS} -Wl,--as-needed, -Wl,--start-group,${CHROMIUM_LIBS} -Wl,--end-group -Wl,--no-as-needed -ldl -lrt -lnss3 -lnssutil3 -lsmime3 -lplds4 -lplc4 -lnspr4 -lpthread -lprotobuf-c -lamp -lwandevent
youtube_la_LDFLAGS=-L@CHROMIUM_BUILD_DIR@ -module -avoid-version -Wl,--no-as-needed -L../../common/ ${CHROMIUM_OBJECTS} -Wl,--as-needed, -Wl,--start-group,${CHROMIUM_LIBS} -Wl,--end-group -Wl,--no-as-needed -ldl -lrt -lnss3 -lnssutil3 -lsmime3 -lplds4 -lplc4 -lnspr4 -lpthread -lprotobuf-c -lamp -lwandevent -lstdc++

# XXX can we combine all object files and static libraries into static library?
#libstaticsdir=$(libdir)/$(PACKAGE)/
#libstatics_LTLIBRARIES=libstatics.la
#nodist_libstatics_la_SOURCES=${CHROMIUM_OBJECTS}

# XXX do i need headless shell lib?

youtube.pb-c.c: Makefile
protoc-c --c_out=. youtube.proto
protoc --python_out=../python/ampsave/tests/ youtube.proto

install-exec-local:
mkdir -p $(libdir)/$(PACKAGE)/extra
cp yt.html $(libdir)/$(PACKAGE)/extra/
Loading

0 comments on commit 4643b71

Please sign in to comment.