From 077c2b3c5401a6c7e4d487cb14d9aed15c419d59 Mon Sep 17 00:00:00 2001 From: Olli Leppanen Date: Fri, 19 Nov 2010 15:18:40 +0200 Subject: [PATCH] Changes: Added pixelchanged test application into package. Enabled "application startup time from application grid" -test case RevBy:Juha Lintula --- debian/applauncherd-testapps.install | 1 + debian/control | 2 +- tests/CMakeLists.txt | 3 + tests/TestApps/pixelchanged/CMakeLists.txt | 13 ++ tests/TestApps/pixelchanged/main.c | 197 +++++++++++++++++++++ tests/TestApps/testapp/main.cpp | 15 +- tests/TestScripts/test-perf.rb | 35 ++-- tests/perftests/tests.xml | 6 +- 8 files changed, 257 insertions(+), 15 deletions(-) create mode 100644 tests/TestApps/pixelchanged/CMakeLists.txt create mode 100644 tests/TestApps/pixelchanged/main.c diff --git a/debian/applauncherd-testapps.install b/debian/applauncherd-testapps.install index 91a9d5e..b08c867 100644 --- a/debian/applauncherd-testapps.install +++ b/debian/applauncherd-testapps.install @@ -15,6 +15,7 @@ usr/bin/fala_wl.launch usr/bin/fala_wol usr/bin/fala_wol.sh usr/bin/fala_gettime +usr/bin/fala_pixelchanged usr/share/dbus-1/services/com.nokia.fala_testapp.service usr/share/dbus-1/services/com.nokia.fala_wl.service usr/share/dbus-1/services/com.nokia.fala_wol.service diff --git a/debian/control b/debian/control index 95aece5..5f19ed8 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: applauncherd Section: admin Priority: important Maintainer: Jussi Lind -Build-Depends: cmake (>= 2.6.0), debhelper (>= 7), libqt4-dev (>= 4.5.0), libmeegotouch-dev, libcreds2-dev [arm armel], aegis-builder (>= 1.4) [arm armel], libwrt-dev +Build-Depends: cmake (>= 2.6.0), debhelper (>= 7), libqt4-dev (>= 4.5.0), libmeegotouch-dev, libcreds2-dev [arm armel], aegis-builder (>= 1.4) [arm armel], libwrt-dev, libxtst-dev, libxext-dev Standards-Version: 3.8.0 Package: applauncherd diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6bd158c..bd583b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,3 +33,6 @@ add_subdirectory(TestApps/fala_status) # Sub build: TestApps add_subdirectory(TestApps/fala_gettime) + +# Sub build: TestApps +add_subdirectory(TestApps/pixelchanged) diff --git a/tests/TestApps/pixelchanged/CMakeLists.txt b/tests/TestApps/pixelchanged/CMakeLists.txt new file mode 100644 index 0000000..f2eff32 --- /dev/null +++ b/tests/TestApps/pixelchanged/CMakeLists.txt @@ -0,0 +1,13 @@ +# Set sources +set(SRC main.c) + +set(CMAKE_CXX_FLAGS "-O3") + +# Link statically to minimize startup time. +set(CMAKE_EXE_LINKER_FLAGS "-lX11 -lXtst") + +add_executable(fala_pixelchanged ${SRC}) + +# Install +install(PROGRAMS fala_pixelchanged DESTINATION /usr/bin/) + diff --git a/tests/TestApps/pixelchanged/main.c b/tests/TestApps/pixelchanged/main.c new file mode 100644 index 0000000..68c9877 --- /dev/null +++ b/tests/TestApps/pixelchanged/main.c @@ -0,0 +1,197 @@ +/* +*XGetImage(Display *display, Drawable d, int x, int y, unsigned + int width, unsigned int height, unsigned long plane_mask, int + format); +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct timeval prevstamp; +char output_filename[1024]; + +void timestamp(char *msg) +{ + struct timeval tim; + FILE *output_file; + char txtbuffer[80]; + + gettimeofday(&tim, NULL); + + snprintf(txtbuffer, 80, "%d%03d ms %s\n", + (int)tim.tv_sec, (int)tim.tv_usec/1000, + msg); + + if (output_filename[0] == '\0') { + printf("%s", txtbuffer); + } else { + if (output_file = fopen(output_filename, "a+")) { + fprintf(output_file, "%s", txtbuffer); + fclose(output_file); + } else { + fprintf(stderr, "pixelchanged: cannot open file '%s' for appending\n", output_filename); + exit(2); + } + } +} + +enum { + SCHEDULER_EVENT_NONE = 0, + SCHEDULER_EVENT_BUTTON, + SCHEDULER_EVENT_KEY, + SCHEDULER_EVENT_MOTION +}; +XDevice* XPointerDevice = NULL; +/** + * Simulates user input event. + * + * @param dpy[in] the display connection. + * @param event[in] the event to simulate. + * @return + */ +void +scheduler_fake_event(Display* dpy, int event_type, int event_param1, int event_param2) { + static int xPos = 0; + static int yPos = 0; + + switch (event_type) { + case SCHEDULER_EVENT_BUTTON: { + int axis[2] = {xPos, yPos}; + XTestFakeDeviceButtonEvent(dpy, XPointerDevice, event_param1, event_param2, axis, 2, CurrentTime); + break; + } + + case SCHEDULER_EVENT_KEY: + XTestFakeDeviceKeyEvent(dpy, XPointerDevice, event_param1, event_param2, NULL, 0, CurrentTime ); + break; + + case SCHEDULER_EVENT_MOTION: + xPos = event_param1; + yPos = event_param2; + { + int axis[2] = {xPos, yPos}; + XTestFakeDeviceMotionEvent(dpy, XPointerDevice, False, 0, axis, 2, CurrentTime); + break; + } + } +} + +/** + * 'Fakes' a mouse click, returning time sent. + */ +void +fake_event(Display *dpy, int x, int y) +{ + if (XPointerDevice) { + scheduler_fake_event(dpy, SCHEDULER_EVENT_MOTION, x, y); + scheduler_fake_event(dpy, SCHEDULER_EVENT_BUTTON, Button1, True); + usleep(5000); + scheduler_fake_event(dpy, SCHEDULER_EVENT_BUTTON, Button1, False); + timestamp("Button1 released"); + } +} + +int main(int argc, char **argv) { + Display *dpy; + int screen = 0; + Window rootw; + XEvent event; + char *DISPLAY = NULL; + XDeviceInfo *devInfo; + char *deviceName; + char txtbuffer[80]; + + int click_x = -1; + int click_y = -1; + unsigned long pixel_value = 0; + int pixel_value_defined = False; + int pixel_x = 423; /* track pixel in the middle of dali display by default */ + int pixel_y = 240; + int quit_when_found = 0; + + int count = 0; + int i = 0; + + int arg = 1; + + output_filename[0] = '\0'; + + while (arg < argc) { + if (0 == strcmp("-c", argv[arg])) { + sscanf(argv[++arg], "%ux%u", &click_x, &click_y); + } else if (0 == strcmp("-p", argv[arg])) { + sscanf(argv[++arg], "%lx", &pixel_value); + pixel_value_defined = True; + } else if (0 == strcmp("-t", argv[arg])) { /* tracked pixel coordinates */ + sscanf(argv[++arg], "%ux%u", &pixel_x, &pixel_y); + } else if (0 == strcmp("-f", argv[arg])) { + sscanf(argv[++arg], "%s", output_filename); + } else if (0 == strcmp("-q", argv[arg])) { + quit_when_found = 1; + } + ++arg; + } + + DISPLAY = (char*)getenv("DISPLAY"); + if (DISPLAY == NULL) { + printf("Cannot open display. DISPLAY variable not set.\n", argv[0]); + exit(1); + } + + dpy = XOpenDisplay(DISPLAY); + screen = XDefaultScreen(dpy); + rootw = RootWindow(dpy, screen); + + /* find out where's the mouse */ + + /* open input device required for XTestFakeDeviceXXX functions */ + if (!(devInfo = XListInputDevices(dpy, &count)) || !count) { + fprintf(stderr, "Cannot input list devices\n"); + return 1; + } + + for (i = 0; i < count; i++) { + if ( devInfo[i].use == IsXExtensionPointer) { + XPointerDevice = XOpenDevice(dpy, devInfo[i].id); + break; + } + } + + + XImage *image; + unsigned long pixel = 0; + unsigned long previous_pixel; + + image = XGetImage(dpy, rootw, pixel_x, pixel_y, 1, 1, AllPlanes, ZPixmap); + previous_pixel = XGetPixel(image, 0, 0); + + if (click_x > -1) + fake_event(dpy, click_x, click_y); + + while (1) { + usleep(50000); /* sleep 50 ms */ + image = XGetImage(dpy, rootw, pixel_x, pixel_y, 1, 1, AllPlanes, ZPixmap); + pixel = XGetPixel(image, 0, 0); + if ( + (!pixel_value_defined && pixel != previous_pixel) + || (pixel_value_defined && pixel == pixel_value) ) { + snprintf(txtbuffer, 80, "pixel changed to value 0x%lx", pixel); + timestamp(txtbuffer); + previous_pixel = pixel; + if (quit_when_found) return 0; + } + } +} diff --git a/tests/TestApps/testapp/main.cpp b/tests/TestApps/testapp/main.cpp index 1075cb3..51f4001 100644 --- a/tests/TestApps/testapp/main.cpp +++ b/tests/TestApps/testapp/main.cpp @@ -65,17 +65,30 @@ int main(int argc, char **argv) { #ifdef HAVE_MCOMPONENTCACHE MApplication* app = MComponentCache::mApplication(argc, argv); + timestamp("app from cache"); MApplicationWindow* w = MComponentCache::mApplicationWindow(); + timestamp("win from cache"); + #else MApplication* app = new MApplication(argc, argv); + timestamp("app created without cache"); + MApplicationWindow* w = new MApplicationWindow; + timestamp("win created without cache"); #endif MyApplicationPage p; + timestamp("page created"); + MApplication::setPrestartMode(M::LazyShutdown); p.setTitle("Applauncherd testapp"); - w->show(); + p.appear(); + timestamp("page.appear() called"); + + w->show(); + timestamp("w->show() called"); + return app->exec(); } diff --git a/tests/TestScripts/test-perf.rb b/tests/TestScripts/test-perf.rb index d3f5d27..7f637a0 100755 --- a/tests/TestScripts/test-perf.rb +++ b/tests/TestScripts/test-perf.rb @@ -29,8 +29,9 @@ class TC_PerformanceTests < Test::Unit::TestCase COUNT = 3 APP_WITH_LAUNCHER = 'fala_wl' APP_WITHOUT_LAUNCHER = 'fala_wol' + PIXELCHANGED_BINARY= '/usr/bin/fala_pixelchanged' TEST_SCRIPT_LOCATION = '/usr/share/applauncherd-testscripts' - PIXELCHANGED_LOG = '/tmp/pixelchanged.log' + PIXELCHANGED_LOG = '/tmp/fala_pixelchanged.log' @start_time = 0 @end_time = 0 @pos = 0 @@ -39,6 +40,8 @@ class TC_PerformanceTests < Test::Unit::TestCase # method called before any test case def setup + + @sut = TDriver.sut(:Id=> 'sut_qt_maemo') if $path.include?("scratchbox") puts "Inside SB, Do Nothing to unlock" else @@ -46,20 +49,25 @@ class TC_PerformanceTests < Test::Unit::TestCase # restart duihome so that qttasserver notices it # NOTE: Remove the cludge after duihome -> meegotouchhome renaming is complete -# if not system("/sbin/initctl restart xsession/duihome") -# system("/sbin/initctl restart xsession/mthome") -# end + if not system("/sbin/initctl restart xsession/duihome") + system("/sbin/initctl restart xsession/mthome") + end system("initctl stop xsession/sysuid") - sleep (5) - end - @sut = TDriver.sut(:Id=> 'sut_qt_maemo') + system("initctl stop xsession/applifed") + + + end + + + end # method called after any test case for cleanup purposes def teardown puts "exit from teardown" system("initctl start xsession/sysuid") + system("initctl start xsession/applifed") end def open_Apps(appName) @@ -67,7 +75,14 @@ class TC_PerformanceTests < Test::Unit::TestCase if FileTest.exists?(PIXELCHANGED_LOG) system "rm #{PIXELCHANGED_LOG}" end - + appOnTop = @sut.application() + while appOnTop.attribute('objectName') != 'meegotouchhome' + fullName = appOnTop.attribute('FullName') + puts "Now killing #{fullName} from the top" + system "pkill #{fullName}" + appOnTop = @sut.application() + end + #Open the Application from the application grid begin @meegoHome = @sut.application(:name => 'duihome') @@ -88,8 +103,8 @@ class TC_PerformanceTests < Test::Unit::TestCase @pos = "#{xpos}x#{ypos}" puts @pos - - system "#{TEST_SCRIPT_LOCATION}/pixelchanged -c #{@pos} -f #{PIXELCHANGED_LOG} -q" + sleep (2) + system "#{PIXELCHANGED_BINARY} -c #{@pos} -f #{PIXELCHANGED_LOG} -q" sleep (4) system "pkill #{appName}" else diff --git a/tests/perftests/tests.xml b/tests/perftests/tests.xml index c26d1f6..6b0195c 100644 --- a/tests/perftests/tests.xml +++ b/tests/perftests/tests.xml @@ -24,12 +24,12 @@ - +