Changes: New functional tests for invoker.

RevBy: Olli Leppanen
pull/1/head
Nimika Keshri 15 years ago
parent 8593d359db
commit c3cba0a91e

@ -1,5 +1,6 @@
usr/bin/fala_ft_hello
usr/bin/fala_status
usr/bin/fala_wait
usr/bin/fala_ft_hello1
usr/bin/fala_ft_hello2
usr/bin/fala_ft_creds1

@ -8,6 +8,7 @@ usr/share/applauncherd-testscripts/test-perf.rb
usr/share/applauncherd-testscripts/get-coordinates.rb
usr/share/applauncherd-testscripts/utils.py
usr/share/applauncherd-testscripts/test-security.py
usr/share/applauncherd-testscripts/test-invoker.py
usr/share/applauncherd-testscripts/test-daemons.py
usr/share/applauncherd-testscripts/test-boot-mode.py
usr/share/applauncherd-testscripts/view.qml

@ -101,6 +101,9 @@ static void sig_forwarder(int sig)
// Send the signal to itself using the default handler
raise(sig);
#ifdef WITH_COVERAGE
__gcov_flush();
#endif
}
}

@ -43,6 +43,9 @@ add_subdirectory(common/unittests)
# Sub build: common/testapps/fala_status
add_subdirectory(common/testapps/fala_status)
# Sub build: common/testapps/fala_wait
add_subdirectory(common/testapps/fala_wait)
# Sub build: common/testapps/focustest
add_subdirectory(common/testapps/focustest)

@ -0,0 +1,32 @@
# Set sources
set(SRC fala_wait.cpp)
link_libraries(${MEEGOTOUCH_LIBRARIES})
include(${QT_USE_FILE})
# Use the compiler and linker flags given in meegotouch-boostable.pc
# in the source tree.
execute_process(COMMAND "env"
"PKG_CONFIG_PATH=${CMAKE_SOURCE_DIR}/data/pkgconfig"
"/usr/bin/pkg-config"
"--cflags"
"meegotouch-boostable"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE booster_cflags
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "env"
"PKG_CONFIG_PATH=${CMAKE_SOURCE_DIR}/data/pkgconfig"
"/usr/bin/pkg-config" "--libs"
"meegotouch-boostable"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE booster_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${booster_cflags}")
set(CMAKE_EXE_LINKER_FLAGS ${booster_libs})
add_executable(fala_wait ${SRC})
# Install
install(PROGRAMS fala_wait DESTINATION /usr/bin/ )

@ -0,0 +1,36 @@
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of applauncherd
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include <MApplication>
#include <MExport>
#include <QTimer>
#include <iostream>
#ifdef HAVE_MCOMPONENTCACHE
#include <mcomponentcache.h>
#endif
M_EXPORT int main(int argc, char ** argv)
{
#ifdef HAVE_MCOMPONENTCACHE
MApplication *app = MComponentCache::mApplication(argc, argv);
#endif
QTimer::singleShot(6000, app, SLOT(quit()));
app->exec();
}

@ -49,6 +49,18 @@
<case name="applauncherd__test_launched_app_name" type="Functional" description="Test that launched application name have .launch at the end" timeout="460" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_launched_app_name</step>
</case>
<case name="applauncherd__test_argv_mbooster_limit" type="Functional" description="Test that ARGV_LIMIT (32) arguments are successfully passed to cached [QM]Application." timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_argv_mbooster_limit</step>
</case>
<case name="applauncherd__test_argv_dbooster_limit" type="Functional" description="Test that ARGV_LIMIT (32) arguments are successfully passed to cached [QM]Application." timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_argv_dbooster_limit</step>
</case>
<case name="applauncherd__test_argv_mbooster_over_limit" type="Functional" description="Test that extra arguments than ARGV_LIMIT are ignored" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_argv_mbooster_over_limit</step>
</case>
<case name="applauncherd__test_argv_dbooster_over_limit" type="Functional" description="Test that extra arguments than ARGV_LIMIT are ignored " timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_argv_mbooster_over_limit </step>
</case>
<!--case name="applauncherd__test_stress_boosted_apps" type="Functional" description="Stress test for boosted applications to check only one instance is running." timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-func-launcher.py test_stress_boosted_apps</step>
@ -128,6 +140,45 @@
<hardware>true</hardware>
</environments>
</set>
<set name="TC_Invoker" description="functional tests for invoker" feature="AF Basic Launcher daemon support" requirement="300168">
<pre_steps>
<step>/usr/bin/waitloadavg.rb -l 1.0 -p 1.0 -t 120</step>
</pre_steps>
<case name="applauncherd__test_invoker_signal_forward" type="Functional" description="Test that UNIX signals are forwarded from invoker to the invoked process" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_invoker_signal_forward</step>
</case>
<case name="applauncherd__test_wrong_type" type="Functional" description="Test that invoker help is printed if application is invoked using a wrong type" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_wrong_type</step>
</case>
<case name="applauncherd__test_unknown_parameter" type="Functional" description="Test that help is printed if unknown parameter is passed to invoker" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_unknown_parameter</step>
</case>
<case name="applauncherd__test_non_existing_binary_launch" type="Functional" description="Test that invoker gives error when it tries to launch a binary that does not exist" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_non_existing_binary_launch</step>
</case>
<case name="applauncherd__test_invoker_symlink" type="Functional" description="Test that the symlink of invoker is unable to launch applications" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_invoker_symlink</step>
</case>
<case name="applauncherd__test_app_link" type="Functional" description="Test that symlink of an application can be launched." timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_app_link</step>
</case>
<case name="applauncherd__test_D_and_G_option" type="Functional" description="Test that -D and -G options work and applications are launcherd" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_D_and_G_option</step>
</case>
<case name="applauncherd__test_app_directory" type="Functional" description="Test that invoker is unable to launch an application which is a directory" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_app_directory</step>
</case>
<case name="applauncherd__test_unsetPATH_launch" type="Functional" description="Test that invoker is unable to launch an application when PATH env is unset" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_unsetPATH_launch</step>
</case>
<case name="applauncherd__test_invoker_wait_term" type="Functional" description="Test that invoker waits for the application to exit" timeout="360" level="System" insignificant="true">
<step expected_result="0">source /tmp/session_bus_address.user; DISPLAY=:0 `pyversions -d` /usr/share/applauncherd-testscripts/test-invoker.py test_invoker_wait_term</step>
</case>
<environments>
<scratchbox>true</scratchbox>
<hardware>true</hardware>
</environments>
</set>
</suite>
</testdefinition>

@ -9,6 +9,7 @@ if ($ENV{HARMATTAN})
test-func-launcher.py
utils.py
test-security.py
test-invoker.py
test-daemons.py
test-single-instance.py
test-core-dump.py

@ -1,3 +1,3 @@
install(PROGRAMS fala_sf_m.sh fala_sf_qt.sh fala_sf_d.sh fala_sf_e.sh DESTINATION /usr/share/applauncherd-testscripts/signal-forward)
install(PROGRAMS fala_sf_m.py fala_sf_qt.py fala_sf_d.py fala_sf_e.py DESTINATION /usr/share/applauncherd-testscripts/signal-forward)
install(PROGRAMS fala_sf_m.py fala_sf_qt.py fala_sf_d.py fala_sf_e.py fala_inv_sf.py DESTINATION /usr/share/applauncherd-testscripts/signal-forward)

@ -0,0 +1,20 @@
#!/usr/bin/env python
import os
import time
import commands
#Launching application from the script
os.system("/usr/share/applauncherd-testscripts/signal-forward/fala_sf_m.sh &")
time.sleep(2)
st, op = commands.getstatusoutput("ps ax | grep fala_ft_hello")
if op.split("\n")[1].find("invoker") != -1:
op = op.split("\n")[1].split(" ")[0]
else:
print("The Application was not launched by invoker")
exit
#Killing application with a signal 11 (Segmentation Fault)
commands.getoutput("kill -11 %s" %op)
time.sleep(2)

@ -549,7 +549,7 @@ class launcher_tests (unittest.TestCase):
time.sleep(3)
debug("The Invoker killed by : <%s>" %op.split ('\n')[-1])
self.assert_(op.split('\n')[-1] == 'Segmentation fault (core dumped)', "The invoker(m-booster) was not killed by the same signal")
self.assert_(op.split('\n')[-1] == 'Segmentation fault', "The invoker(m-booster) was not killed by the same signal")
time.sleep(2)
#Test for d-booster
@ -577,7 +577,7 @@ class launcher_tests (unittest.TestCase):
time.sleep(3)
debug("The Invoker killed by : %s" %op.split('\n')[-1])
self.assert_(op.split('\n')[-1] == 'Aborted (core dumped)', "The invoker(q-booster) was not killed by the same signal")
self.assert_(op.split('\n')[-1] == 'Aborted', "The invoker(q-booster) was not killed by the same signal")
time.sleep(2)
def test_launch_wo_applauncherd(self):

@ -0,0 +1,197 @@
#!/usr/bin/env python
#
# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved.
# Contact: Nokia Corporation (directui@nokia.com)
#
# This file is part of applauncherd.
#
# If you have questions regarding the use of this file, please contact
# Nokia at directui@nokia.com.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation
# and appearing in the file LICENSE.LGPL included in the packaging
# of this file.
"""
This program tests the functionalities of invoker
Authors: nimika.1.keshri@nokia.com
"""
import os, os.path, glob
import subprocess
import commands
import time
import sys
import unittest
import re
from subprocess import Popen
from utils import *
from os.path import basename
class InvokerTests(unittest.TestCase):
def setUp(self):
debug("setUp")
if get_pid('applauncherd') == None:
start_applauncherd()
def tearDown(self):
debug("tearDown")
if get_pid('applauncherd') == None:
start_applauncherd()
wait_for_single_applauncherd()
#Testcases
def test_invoker_signal_forward(self):
"""
Test that UNIX signals are forwarded from
invoker to the invoked process
"""
st, op = commands.getstatusoutput("/usr/share/applauncherd-testscripts/signal-forward/fala_inv_sf.py")
time.sleep(3)
debug("The Invoker killed by : <%s>" %op)
self.assert_(op == 'Segmentation fault', "The invoker(m-booster) was not killed by the same signal")
time.sleep(2)
def test_wrong_type(self):
"""
Test that invoker help is printed if application is
invoked using a wrong type
"""
cmd = '/usr/bin/invoker --type=f /usr/bin/fala_wl'
debug("Launch application with wrong type %s" %cmd)
st, op = commands.getstatusoutput('su - user -c "%s"' %cmd)
self.assert_(op.split("\n")[0] == 'invoker: error: Unknown application type: f ',"No Error displayed")
self.assert_(op.split("\n")[2] == 'Usage: invoker [options] [--type=TYPE] [file] [args]',"No usgae displayed")
def test_unknown_parameter(self):
"""
Test that help is printed if unknown parameter
is passed to invoker
"""
cmd = '/usr/bin/invoker --type=m --x /usr/bin/fala_wl'
debug("Launch application with wrong option %s" %cmd)
st, op = commands.getstatusoutput('su - user -c "%s"' %cmd)
self.assert_(op.split("\n")[2] == 'Usage: invoker [options] [--type=TYPE] [file] [args]',"No usage displayed")
def test_non_existing_binary_launch(self):
"""
Test that invoker gives error when it tries to launch
a binary that does not exist
"""
cmd = '/usr/bin/invoker --type=m /usr/bin/fala_foo'
debug("Launch a non existing application %s" %cmd)
st, op = commands.getstatusoutput('su - user -c "%s"' %cmd)
self.assert_(st != 0,"The application was launched")
def test_invoker_symlink(self):
"""
Test that the symlink of invoker is unable to launch applications
"""
os.system("ln -s /usr/bin/invoker /usr/bin/invoker_link")
cmd = "/usr/bin/invoker_link --type=m /usr/bin/fala_wl"
st, op = commands.getstatusoutput('su - user -c "%s"' %cmd)
os.system("rm /usr/bin/invoker_link")
self.assert_(st != 0,"The application was launched")
def test_app_link(self):
"""
Test that symlink of an application can be launched.
"""
os.system("ln -s /usr/bin/fala_wl /usr/bin/fala_link")
cmd = "/usr/bin/invoker --type=m /usr/bin/fala_link"
os.system('su - user -c "%s"&' %cmd)
pid = get_pid("fala_link")
os.system("rm /usr/bin/fala_link")
kill_process("fala_link")
self.assert_(pid != None ,"The application was not launched")
def test_D_and_G_option(self):
"""
Test that -D and -G options work and applications are launcherd
-G = INVOKER_MSG_MAGIC_OPTION_DLOPEN_GLOBAL
-D = INVOKER_MSG_MAGIC_OPTION_DLOPEN_DEEP
"""
p = run_app_as_user_with_invoker("/usr/bin/fala_wl", booster='m', arg = '-G')
time.sleep(3)
pid = p.pid
kill_process("fala_wl")
self.assert_(pid != None ,"The application was not launched")
p = run_app_as_user_with_invoker("/usr/bin/fala_wl", booster='m', arg = '-D')
time.sleep(3)
pid = p.pid
kill_process("fala_wl")
self.assert_(pid != None ,"The application was not launched")
def test_app_directory_file(self):
"""
Test that invoker is unable to launch a application which is a directory
"""
#Test for a directory
os.system("mkdir /usr/bin/fala_dir")
st, op = commands.getstatusoutput("/usr/bin/invoker --type=m /usr/bin/fala_dir")
time.sleep(3)
os.system("rm -rf /usr/bin/fala_dir")
self.assert_(st != 0 ,"The application was not launched")
def test_unsetPATH_launch(self):
"""
Unset the PATH env variable and try to launch an application with
relative path. The launch should fail
"""
st, op = commands.getstatusoutput("(unset PATH;/usr/bin/invoker --type=m fala_wl)")
self.assert_(st != 0, "The application was launched")
self.assert_(op == "invoker: died: could not get PATH environment variable", "The application was launched")
def test_invoker_wait_term(self):
"""
start application with --wait-term parameter.
Check that application is started and invoker is waiting termination before exit
"""
# launch an app with invoker --wait-term
debug("launching fala_wait ...")
p = Popen(['/usr/bin/invoker', '--type=m', '--wait-term',
'/usr/bin/fala_wait'],
shell=False,
stdout=DEV_NULL, stderr=DEV_NULL)
# wait a little
debug("waiting ...")
time.sleep(5)
success = True
if p.poll() == None:
debug("NOT DEAD")
else:
debug("DEAD")
success = False
debug("waiting for invoker to terminate ...")
p.wait()
debug("terminating fala_wait ...")
self.assert_(success, "invoker terminated before delay elapsed")
# main
if __name__ == '__main__':
# When run with testrunner, for some reason the PATH doesn't include
# the tools/bin directory
if os.getenv('_SBOX_DIR') != None:
os.environ['PATH'] = os.getenv('PATH') + ":" + os.getenv('_SBOX_DIR') + '/tools/bin'
using_scratchbox = True
tests = sys.argv[1:]
mysuite = unittest.TestSuite(map(InvokerTests, tests))
result = unittest.TextTestRunner(verbosity=2).run(mysuite)
if not result.wasSuccessful():
sys.exit(1)
sys.exit(0)

@ -89,7 +89,7 @@ def run_app_as_user_with_invoker(appname, booster = 'm', arg = "", out = DEV_NUL
Runs the specified app as a user.
"""
inv_cmd = "/usr/bin/invoker --type=%s %s %s" %(booster,arg, appname)
debug("run %s as user" %appname)
debug("run %s as user" %inv_cmd)
cmd = ['su', '-', 'user', '-c']
if type(appname) == list:
cmd += inv_cmd

Loading…
Cancel
Save