From 13bc48e7494da66978c4ff12c459bbf09482e322 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Xuan Pham Date: Sat, 30 May 2020 06:32:28 +0700 Subject: [PATCH 1/5] [UPGRADE][GEdit] define steps to test with gedit --- .../steps/0000_install_gedit_for_testing.sh | 9 ++++++++ .../0001_verify_unikey_without_valgrind.sh | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/gedit/steps/0000_install_gedit_for_testing.sh create mode 100644 tests/gedit/steps/0001_verify_unikey_without_valgrind.sh diff --git a/tests/gedit/steps/0000_install_gedit_for_testing.sh b/tests/gedit/steps/0000_install_gedit_for_testing.sh new file mode 100644 index 000000000..fb3346683 --- /dev/null +++ b/tests/gedit/steps/0000_install_gedit_for_testing.sh @@ -0,0 +1,9 @@ +#!/bin/bash +ROOT="$(git rev-parse --show-toplevel)" + +source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Console.sh + +if ! install_package_to_test_machine gedit; then + error "can't install gedit to $MACHINE" +fi diff --git a/tests/gedit/steps/0001_verify_unikey_without_valgrind.sh b/tests/gedit/steps/0001_verify_unikey_without_valgrind.sh new file mode 100644 index 000000000..ea3c3980c --- /dev/null +++ b/tests/gedit/steps/0001_verify_unikey_without_valgrind.sh @@ -0,0 +1,21 @@ +#!/bin/bash +ROOT="$(git rev-parse --show-toplevel)" + +source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Console.sh + +for CASE in $(ls -1c $SUITE); do + EXT="${CASE##*.}" + + if [ $EXT = "py" ]; then + if ! copy_to_test_machine $SUITE/$CASE; then + error "can't copy $SUITE/$CASE to $MACHINE" + fi + + warning "run test case $CASE" + + if ! exec_on_test_machine 60 "DISPLAY=:0 python ~/$CASE"; then + error "fail test case $CASE" + fi + fi +done From b1464e6cf7f64187250c9dda6b56737611fca513 Mon Sep 17 00:00:00 2001 From: hung0913208 Date: Sun, 31 May 2020 15:53:08 +0700 Subject: [PATCH 2/5] [UPGRADE][GEdit] test typing keyboard with gedit (#4) Description: - Define a sample example of how to build a UI automation test case with dogtail and gedit Signed-off-by: Hung Nguyen Xuan Pham --- .github/workflows/regression.yaml | 27 ------ tests/gedit/test_use_keyboard_for_typing.py | 98 +++++++++++++++++++++ 2 files changed, 98 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/regression.yaml create mode 100644 tests/gedit/test_use_keyboard_for_typing.py diff --git a/.github/workflows/regression.yaml b/.github/workflows/regression.yaml deleted file mode 100644 index bec2b62d7..000000000 --- a/.github/workflows/regression.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: Check if the new PR is working well - -on: - pull_request: - branchs: - - master - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - cxx: [g++] - - steps: - - uses: actions/checkout@v2 - - name: update - run: sudo apt update - - name: prepare - run: while ! sudo apt install qemu; do if ! which qemu-system-x86_64; then sleep 1; else break; fi; done - - name: fetch base libraries - run: ./tests/pipeline/prepare.sh --dry-run - - name: build and test - env: - CXX: ${{ matrix.cxx }} - MEGA: ${{ secrets.MEGA }} - run: ./Base/Tests/Pipeline/Create.sh diff --git a/tests/gedit/test_use_keyboard_for_typing.py b/tests/gedit/test_use_keyboard_for_typing.py new file mode 100644 index 000000000..e0477d713 --- /dev/null +++ b/tests/gedit/test_use_keyboard_for_typing.py @@ -0,0 +1,98 @@ +import unittest, os, signal + +from dogtail import tree +from dogtail.config import config +from dogtail.procedural import focus, click, run +from dogtail.rawinput import typeText +from dogtail.utils import screenshot +from dogtail.predicate import GenericPredicate + +# @NOTE: i'm considering move these function to be as gedit helpers so we +# can reuse them to many more test-cases + +def run_ui_typing_helper(cache, text): + if os.path.isfile(cache): + os.remove(cache) + + pid = run('gedit') + gedit = tree.root.application('gedit') + saved = False + ready_to_save = False + + try: + focus.application('gedit') + + focus.text() + typeText(text) + + # Click gedit's Save button. + click.button('Save') + + try: + # Focus gedit's Save As... dialog + + focus.widget.findByPredicate(GenericPredicate(roleName='file chooser')) + finally: + ready_to_save = True + except FocusError as error: + try: + # This string changed somewhere around gedit 2.13.2. + # This is the new string + + focus.dialog('Save As\u2026') + except FocusError: + # Fall back to the old string. + + focus.dialog('Save as...') + finally: + ready_to_save = True + finally: + try: + if ready_to_save: + try: + typeText(cache) + click('Save') + finally: + saved = True + + # Let's quit now. + try: + click('File') + except Exception as error: + print(error) + finally: + click('Quit') + except Exception as error: + print(error) + os.kill(pid, signal.SIGKILL) + + if saved: + with open(cache) as fd: + return fd.read() + else: + return None + +class TestKeyboardTyping(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(TestKeyboardTyping, self).__init__(*args, **kwargs) + + def test_typing_to_gedit(self): + steps = [ + ('i\'m typing \'hello world\' using dogtail', + 'i\'m typing \'hello world\' using dogtail\n') + ] + + for typing, expect in steps: + result = run_ui_typing_helper('/tmp/test_typing_to_gedit.txt', + typing) + self.assertEqual(result, expect) + +if __name__ == '__main__': + #import dogtail.i18n + #dogtail.i18n.loadTranslationsFromPackageMoFiles('gedit') + + #config.debugSleep = True + #config.debugSearching = True + #config.debugTranslation = True + + unittest.main() From 188309f23c6978b532f3e84ceff4e0d78a4100cb Mon Sep 17 00:00:00 2001 From: Hung Nguyen Xuan Pham Date: Sun, 31 May 2020 18:48:25 +0700 Subject: [PATCH 3/5] [UPGRADE][Pipeline] add README.MD Description: - Add README.MD to instruct how to use this pipeline and how to troubleshoot with the VM using VNC services. Signed-off-by: Hung Nguyen Xuan Pham --- tests/README.MD | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/README.MD diff --git a/tests/README.MD b/tests/README.MD new file mode 100644 index 000000000..c7806da32 --- /dev/null +++ b/tests/README.MD @@ -0,0 +1,33 @@ +## Hướng dẫn cách thêm một test case mới vào để test với UI automation test. +Mặc định, mọi thư mục trong **./tests** đều đươc xem là một suite riêng biệt (ngoại trừ thư mục pipeline dùng để chứa các script cài đặt và cấu hình máy ảo để test) và để đơn giản hóa, chúng ta chia các suite này theo các application cụ thể để test. +Mỗi suite cần có thư mục **steps** để báo rằng đây là một suite chỉ dành cho UI test thôi. Bên trong steps sẽ chứa các bước cần để chạy test trên môi trường máy ảo được cài sẵn, chi tiết có thể tham khảo ví dụ mẫu về gedit. + +## Lưu ý trước khi viết một test case mới +Test case hiện chỉ hỗ trợ dogtail vì hiện tại ubuntu latest không còn hỗ trợ các UI Automation khác như ldtp hay autopilot để test. Lý do chọn dogtail là vì hiện vẫn hỗ trợ tốt cho việc test các tác vụ tương đối đơn giản và chạy tốt trên cả gnome lẫn kde nên việc viết testcase sẽ đơn giản hơn. + +## Cách để hỗ trợ một distro mới + Mặc định, pipeline hiện chỉ hỗ trợ test trên ubuntu. Tuy nhiên, pipeline được thiết kế nhắm tới hỗ trợ cho nhiều distro khác nhau và với nhiều các khởi động khác nhau nhưng chủ yếu là dùng LiveCD để boot một máy ảo qemu không đĩa từ network và chạy test case. Mỗi distro cần được định nghĩa trong một file riêng trong thư mục ./tests/pipeline/environments với tên trùng với distro mà ta muốn hỗ trợ. + Mỗi file trong thư mục tests/pipeline/environments cần định nghĩa rõ các thành phần sau: + - Hàm **fetch**: được gọi đầu tiên để download ISO image xuống máy test, pipeline tự sẽ biết để giải nén file ISO ra thành các phần cần thiết cho công việc chỉnh sửa và build một ISO image mới. + - Hàm **extract**: được dùng để giải nén ra rootfs từ ISO image, mặc định các LiveCD đều chứa rootfs bên trong các file squashfs. + - Hàm **configure**: được thực thi trực tiếp trên rootfs thông qua chroot để chỉnh sửa trực tiếp trên chính rootfs này. Ta có thể thêm bớt các thành phần cần thiết cho việc xây dựng một LiveCD riêng. Ở đây, pipeline chỉ cấu hình thêm dịch vụ ssh, cài dogtail cho việc test, cài password cho root là rootroot và cấu hình /etc/resolv.conf để dùng Google DNS. Lưu ý, luôn phải cấu hình account **root** là **rootroot** vì pipeline sẽ dùng account này để đăng nhập trực tiếp vào máy ảo để cấu hình LiveCD account mặc định. + - Hàm **finish**: dùng để chỉnh sửa các phần không thuộc rootfs như thực hiện md5sum để cập nhật md5 mới của filesystem.squashfs hay cập nhật danh sách các deb đã được cài vào trong LiveCD. + - Hàm **is_fully_started**: dùng để pipeline liên tục check vào máy ảo để xác định khi nào GUI đã thực sự sẵn sàng để test. + - Hàm **version**: dùng để lấy mã latest version của distro tương ứng. + - Hàm **username**: trả về username mặc định của LiveCD, với **ubuntu** account mặc định là **ubuntu** + - Hàm **password**: trả về password bạn muốn dùng cho account mặc định của LiveCD. + - Hàm **interface**: trả về interface dùng để boot, hiện hàm này không thực sự cần thiết do nfs-ganesha gặp lỗi với nfs3 nên không thể dùng để boot các máy ảo lên. + +#### Có thể tham khảo chi tiết qua file tests/pipeline/environments/ubuntu. + +## Cách cấu hình một travis-ci mới +Bạn cần cung cấp các environment variables sau để pipeline có thể biết mà hỗ trợ bạn. +- PROJECT: tên của project hiện tại mặc định là ibus-unikey, biến này được dùng để truy cập vào storage để lấy các bản build tương ứng cho từng distro. +- MEGA: chứa username, password để đăng nhập, download và upload các bản build cho từng distro. Biến này nên được viết theo cấu trúc sau MEGA=email:password. Nên cấu hình biến này để tối ưu hóa quá trình chạy của pipeline vì khi đó các bản build sẽ được lưu vào mega.co.nz để tránh việc tốn thời gian cho việc build các file squashfs vốn tốn hầu như quá 50% thời gian chạy của pipeline. +- NGROK: chứa token của dịch vụ ngrok.com, pipeline nếu thấy biến môi trường này sẽ tự mở một localtunnel tới thẳng tới cổng VNC của máy ảo giúp bạn có thể theo dõi quá trình chạy của máy ảo. +- INTERACT: cờ dùng để khống chế pipeline sẽ tự thoát (set bằng 0) hay không (set lên 1)sau khi việc test hoàn tất. Mặc định là tự thoát. + +#### Tất cả các biến môi trường này đều là optional nhưng nên cân nhắc cấu hình tùy theo tình huống cụ thể để giúp việc phát triển dự án tốt hơn. + +## Các để kết nối VNC với pipeline +Có thể dùng http://allmydesktops.com/ để kết nối với vnc của máy ảo ngay khi pipeline mở localtunnel. Password của vnc luôn luôn là rootroot. \ No newline at end of file From ccee9a0b11a25c393e4e813cf582d39d04740bc5 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Xuan Pham Date: Sun, 31 May 2020 19:02:03 +0700 Subject: [PATCH 4/5] [UPGRADE][Pipeline] ignore files or console suites Description: - Detect which suite is configured to be UI suites and do it separatly. Signed-off-by: Hung Nguyen Xuan Pham --- tests/pipeline/test.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pipeline/test.sh b/tests/pipeline/test.sh index 8e8f31463..78b50e972 100755 --- a/tests/pipeline/test.sh +++ b/tests/pipeline/test.sh @@ -100,6 +100,10 @@ for DISTRO in $(ls -1c $ROOT/tests/pipeline/environments); do for ITEM in $(ls -1c $ROOT/tests); do if [ $ITEM = "pipeline" ]; then continue + elif [ ! -d $ROOT/tests/$ITEM ]; then + continue + elif [ ! -d $ROOT/tests/$ITEM/steps ]; then + continue fi export SUITE="$ROOT/tests/$ITEM" From 469496896ab1989684d2603dd90bbe55a64e51fa Mon Sep 17 00:00:00 2001 From: hung0913208 Date: Tue, 9 Jun 2020 22:48:32 +0700 Subject: [PATCH 5/5] [ENHANCE] install ibus unikey to virtual machine (#5) Description: - This PR helps to test ibus-unikey automatically on gedit using dogtail. On the previous commits, i just don't how to run test cases automatically without any real test with the current project. This commit should finish off what i'm still unfinishing. Known issues: - Since we are mainly using travis-ci for testing enduser cases using virtual machine, timing issues are big problem like clicking doesn't work or saving take so much time to finish. - Dogtail might stucks when we try with gnome-terminal - Typing is stucked or hanged a litter bit, this issue didn't happen when we test without ibus-unikey. Signed-off-by: Hung Nguyen Xuan Pham --- .../steps/0000_install_gedit_for_testing.sh | 1 + .../gedit/steps/0001_install_mate_terminal.sh | 19 +++ ...> 0002_copy_test_cases_to_test_machine.sh} | 11 +- .../0003_verify_unikey_without_valgrind.sh | 46 ++++++++ .../9999_clear_everything_after_finish.sh | 11 ++ tests/gedit/test_use_keyboard_for_typing.py | 111 ++++++++---------- tests/pipeline/build.sh | 6 +- tests/pipeline/environments/ubuntu | 20 +++- tests/pipeline/libraries/Console.sh | 72 +++++++++++- tests/pipeline/test.sh | 63 ++++++++-- 10 files changed, 271 insertions(+), 89 deletions(-) create mode 100644 tests/gedit/steps/0001_install_mate_terminal.sh rename tests/gedit/steps/{0001_verify_unikey_without_valgrind.sh => 0002_copy_test_cases_to_test_machine.sh} (71%) create mode 100644 tests/gedit/steps/0003_verify_unikey_without_valgrind.sh create mode 100644 tests/gedit/steps/9999_clear_everything_after_finish.sh diff --git a/tests/gedit/steps/0000_install_gedit_for_testing.sh b/tests/gedit/steps/0000_install_gedit_for_testing.sh index fb3346683..13f0b3a81 100644 --- a/tests/gedit/steps/0000_install_gedit_for_testing.sh +++ b/tests/gedit/steps/0000_install_gedit_for_testing.sh @@ -7,3 +7,4 @@ source $ROOT/tests/pipeline/libraries/Console.sh if ! install_package_to_test_machine gedit; then error "can't install gedit to $MACHINE" fi + diff --git a/tests/gedit/steps/0001_install_mate_terminal.sh b/tests/gedit/steps/0001_install_mate_terminal.sh new file mode 100644 index 000000000..b02e090bf --- /dev/null +++ b/tests/gedit/steps/0001_install_mate_terminal.sh @@ -0,0 +1,19 @@ +#!/bin/bash +ROOT="$(git rev-parse --show-toplevel)" +BUILDER="/home/$(username)/ibus-unikey/Base/Tools/Builder/build" +CURRENT=$(pwd) + +source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Package.sh +source $ROOT/tests/pipeline/libraries/Console.sh + +rm -fr $ROOT/build + +if ! exec_on_test_machine_without_output "sudo apt install -y mate-terminal"; then + # @NOTE: this package is essential since i found that gnome-terminal can't be + # detected by dogtail. It should be possible issue from this framework only + # and it should be fixed later so this workaround is applied to overcome this + + error "can't install \`mate-terminal\` onto $MACHINE" +fi + diff --git a/tests/gedit/steps/0001_verify_unikey_without_valgrind.sh b/tests/gedit/steps/0002_copy_test_cases_to_test_machine.sh similarity index 71% rename from tests/gedit/steps/0001_verify_unikey_without_valgrind.sh rename to tests/gedit/steps/0002_copy_test_cases_to_test_machine.sh index ea3c3980c..1a5612524 100644 --- a/tests/gedit/steps/0001_verify_unikey_without_valgrind.sh +++ b/tests/gedit/steps/0002_copy_test_cases_to_test_machine.sh @@ -1,21 +1,18 @@ #!/bin/bash ROOT="$(git rev-parse --show-toplevel)" +CURRENT=$(pwd) source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Package.sh source $ROOT/tests/pipeline/libraries/Console.sh for CASE in $(ls -1c $SUITE); do EXT="${CASE##*.}" - + if [ $EXT = "py" ]; then if ! copy_to_test_machine $SUITE/$CASE; then error "can't copy $SUITE/$CASE to $MACHINE" fi - - warning "run test case $CASE" - - if ! exec_on_test_machine 60 "DISPLAY=:0 python ~/$CASE"; then - error "fail test case $CASE" - fi fi done + diff --git a/tests/gedit/steps/0003_verify_unikey_without_valgrind.sh b/tests/gedit/steps/0003_verify_unikey_without_valgrind.sh new file mode 100644 index 000000000..22e666c56 --- /dev/null +++ b/tests/gedit/steps/0003_verify_unikey_without_valgrind.sh @@ -0,0 +1,46 @@ +#!/bin/bash +ROOT="$(git rev-parse --show-toplevel)" +BUILDER="/home/$(username)/ibus-unikey/Base/Tools/Builder/build" +CURRENT=$(pwd) + +source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Package.sh +source $ROOT/tests/pipeline/libraries/Console.sh + +SPECs=("Sanitize" "Debug") + +for SPEC in ${SPECs[@]}; do + METHODs=('telex') + + info "start testing with build mode $SPEC" + + DEFAULT_ENGINE=$(exec_on_test_machine "DISPLAY=:0 GTK_IM_MODULE=ibus ibus engine") + + if ! exec_on_test_machine_without_output "cd ~/ibus-unikey/build/$SPEC && sudo make install"; then + error "can't install to /home/$(username)/$SPEC" + elif ! exec_on_test_machine "DISPLAY=:0 GTK_IM_MODULE=ibus ibus engine Unikey"; then + error "can't switch to use ibus-unikey" + fi + + for METHOD in ${METHODs[@]}; do + if ! exec_on_test_machine "DISPLAY=:0 GTK_IM_MODULE=ibus gsettings set org.freedesktop.ibus.engine.unikey input-method $METHOD"; then + error "can't switch to method $METHOD" + fi + + for CASE in $(ls -1c $SUITE); do + EXT="${CASE##*.}" + + if [ $EXT = "py" ]; then + warning "run test case $CASE" + + if ! exec_on_test_machine "DISPLAY=:0 GTK_IM_MODULE=ibus python ~/$CASE $METHOD"; then + error "fail stressing test case $CASE" + fi + fi + done + done + + if ! exec_on_test_machine "DISPLAY=:0 GTK_IM_MODULE=ibus ibus engine $DEFAULT_ENGINE"; then + error "can't switch back to default engine $DEFAULT_ENGINE" + fi +done diff --git a/tests/gedit/steps/9999_clear_everything_after_finish.sh b/tests/gedit/steps/9999_clear_everything_after_finish.sh new file mode 100644 index 000000000..58b41a63b --- /dev/null +++ b/tests/gedit/steps/9999_clear_everything_after_finish.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +ROOT="$(git rev-parse --show-toplevel)" +BUILDER="/home/$(username)/ibus-unikey/Base/Tools/Builder/build" +CURRENT=$(pwd) + +source $ROOT/tests/pipeline/libraries/Logcat.sh +source $ROOT/tests/pipeline/libraries/Package.sh +source $ROOT/tests/pipeline/libraries/Console.sh + +exec_on_test_machine 'rm -fr ~/\*.py' diff --git a/tests/gedit/test_use_keyboard_for_typing.py b/tests/gedit/test_use_keyboard_for_typing.py index e0477d713..1a6cd0e7e 100644 --- a/tests/gedit/test_use_keyboard_for_typing.py +++ b/tests/gedit/test_use_keyboard_for_typing.py @@ -1,91 +1,66 @@ -import unittest, os, signal +import unittest, os, signal, sys, time from dogtail import tree from dogtail.config import config -from dogtail.procedural import focus, click, run -from dogtail.rawinput import typeText +from dogtail.procedural import focus, click, run, FocusWidget, FocusDialog, FocusWindow, FocusApplication, FocusError +from dogtail.rawinput import typeText, keyCombo from dogtail.utils import screenshot from dogtail.predicate import GenericPredicate # @NOTE: i'm considering move these function to be as gedit helpers so we # can reuse them to many more test-cases +method = 'telex' + def run_ui_typing_helper(cache, text): if os.path.isfile(cache): os.remove(cache) - pid = run('gedit') + pid = run('gedit {}'.format(cache)) gedit = tree.root.application('gedit') - saved = False - ready_to_save = False - - try: - focus.application('gedit') - - focus.text() - typeText(text) - - # Click gedit's Save button. - click.button('Save') - - try: - # Focus gedit's Save As... dialog - - focus.widget.findByPredicate(GenericPredicate(roleName='file chooser')) - finally: - ready_to_save = True - except FocusError as error: - try: - # This string changed somewhere around gedit 2.13.2. - # This is the new string - - focus.dialog('Save As\u2026') - except FocusError: - # Fall back to the old string. - focus.dialog('Save as...') - finally: - ready_to_save = True - finally: - try: - if ready_to_save: - try: - typeText(cache) - click('Save') - finally: - saved = True + focus.application('gedit') + focus.text() + typeText(text) + + keyCombo('s') - # Let's quit now. - try: - click('File') - except Exception as error: - print(error) - finally: - click('Quit') - except Exception as error: - print(error) - os.kill(pid, signal.SIGKILL) + try: + # @NOTE: maybe we can't access the menu and click the + # item `Quit` at menu `File` + + click.menu('File') + click.menuItem('Quit') + except Exception as error: + keyCombo('q') - if saved: + try: with open(cache) as fd: return fd.read() - else: + except Exception as error: + os.kill(pid, signal.SIGKILL) return None class TestKeyboardTyping(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestKeyboardTyping, self).__init__(*args, **kwargs) - def test_typing_to_gedit(self): - steps = [ - ('i\'m typing \'hello world\' using dogtail', - 'i\'m typing \'hello world\' using dogtail\n') - ] - - for typing, expect in steps: - result = run_ui_typing_helper('/tmp/test_typing_to_gedit.txt', - typing) - self.assertEqual(result, expect) + def test_typing_vietnamese_style(self): + if method == 'telex': + steps = [ + ('xin chaof, tooi laf mootj con autobot dduowcj xaay duwngj ddeer tesst ibus', + 'xin chào, tôi là một con autobot được xây dựng để test ibus\n') + ] + elif method == 'vni': + steps = [ + ('xin chao2, to6i la2 mo65t con autobot d9uo75c xa6y du7ng5 d9e63 test ibus', + 'xin chào, tôi là một con autobot được xây dựng để test ibus\n') + ] + + for _ in range(loop): + for typing, expect in steps: + self.assertEqual(run_ui_typing_helper('/tmp/0001.txt', typing), + expect) if __name__ == '__main__': #import dogtail.i18n @@ -94,5 +69,15 @@ def test_typing_to_gedit(self): #config.debugSleep = True #config.debugSearching = True #config.debugTranslation = True + #config.actionDelay = 0.1 + if len(sys.argv) > 2: + loop = int(sys.argv.pop()) + else: + loop = 1 + + if len(sys.argv) > 1: + method = sys.argv.pop() + else: + method = 'telex' unittest.main() diff --git a/tests/pipeline/build.sh b/tests/pipeline/build.sh index 07d6995a1..0de98148f 100755 --- a/tests/pipeline/build.sh +++ b/tests/pipeline/build.sh @@ -27,10 +27,6 @@ if [ $(which git) ]; then ROOT="$(git rev-parse --show-toplevel)" BUILDER=$ROOT/Base/Tools/Builder/build - if ! $BUILDER --root $ROOT --debug 1 --rebuild 0 --mode $MODE; then - exit -1 - fi - if [[ $MODE -eq 1 ]] && [[ ${#NODE} -gt 0 ]]; then FORCE=0 OTYPE="iso" @@ -319,6 +315,8 @@ EOF $SU chmod -R 755 $ROOT/pxeboot info "going to test with virtual machine" + elif ! $BUILDER --root $ROOT --debug 1 --rebuild 0 --mode $MODE; then + exit -1 fi else error "Please install git first" diff --git a/tests/pipeline/environments/ubuntu b/tests/pipeline/environments/ubuntu index bfaddf14d..c49c5698a 100644 --- a/tests/pipeline/environments/ubuntu +++ b/tests/pipeline/environments/ubuntu @@ -78,9 +78,9 @@ function extract() { } function is_fully_started() { - if ! sshpass -p rootroot ssh -o LogLevel=QUIET root@$1 'ps -aux | grep nautilus | grep -v grep' &> /dev/null; then + if ! sshpass -p rootroot ssh -o LogLevel=QUIET root@$1 'ps -aux | grep ibus-daemon | grep -v grep' &> /dev/null; then return -1 - elif ! sshpass -p ubuntu ssh -o LogLevel=QUIET ubuntu@$1 'gsettings set org.gnome.desktop.interface toolkit-accessibility true' &> /dev/null; then + elif ! sshpass -p ubuntu ssh -o LogLevel=QUIET ubuntu@$1 'gsettings set org.gnome.desktop.interface toolkit-accessibility true'; then return -1 else sleep 10 @@ -112,6 +112,22 @@ nameserver 8.8.4.4 error "can't use \`add-apt-repository universe\`" elif ! sudo apt update &> /dev/null; then error "can't use \`apt-get update\`" + elif ! sudo apt install -y git &> /dev/null; then + error "can't run \`apt-get install -y git\`" + elif ! sudo apt install -y lcov &> /dev/null; then + error "can't run \`apt-get install -y lcov\`" + elif ! sudo apt install -y build-essential &> /dev/null; then + error "can't run \`apt-get install -y build-essential\`" + elif ! sudo apt install -y build-essential &> /dev/null; then + error "can't run \`apt-get install -y build-essential\`" + elif ! sudo apt install -y libibus-1.0-dev &> /dev/null; then + error "can't run \`apt-get install -y libibus-1.0-dev\`" + elif ! sudo apt install -y libgtk-3-dev &> /dev/null; then + error "can't run \`apt-get install -y libgtk-3-dev\`" + elif ! sudo apt install -y gettext &> /dev/null; then + error "can't run \`apt-get install -y gettext\`" + elif ! sudo apt install -y cmake &> /dev/null; then + error "can't run \`apt-get install -y cmake\`" elif ! sudo apt install -y openssh-server &> /dev/null; then error "can't run \`apt-get install -y openssh-server\`" elif ! sudo apt install -y python3-dogtail &> /dev/null; then diff --git a/tests/pipeline/libraries/Console.sh b/tests/pipeline/libraries/Console.sh index e7bf36ba5..7aae3ea44 100644 --- a/tests/pipeline/libraries/Console.sh +++ b/tests/pipeline/libraries/Console.sh @@ -1,6 +1,8 @@ #!/bin/bash ROOT="$(git rev-parse --show-toplevel)" +source $ROOT/tests/pipeline/libraries/Package.sh + function copy_to_test_machine() { if [[ ${#MACHINE} -gt 0 ]]; then source $ROOT/tests/pipeline/environments/$MACHINE @@ -20,7 +22,24 @@ function copy_to_test_machine() { return -4 fi } - + +function rsync_to_test_machine() { + INPUT=$1 + shift + + if [[ ${#MACHINE} -gt 0 ]]; then + source $ROOT/tests/pipeline/environments/$MACHINE + else + return -1 + fi + + if [[ ${#ADDRESS} -gt 0 ]]; then + if ! sshpass -p $(password) rsync $@ -a $INPUT $(username)@$ADDRESS:~/; then + return -2 + fi + fi +} + function exec_on_test_machine() { if [[ ${#MACHINE} -gt 0 ]]; then source $ROOT/tests/pipeline/environments/$MACHINE @@ -28,14 +47,58 @@ function exec_on_test_machine() { return -1 fi + while [ $# -gt 0 ]; do + case $1 in + --timeout) TIMEOUT="$2"; shift;; + --add-arg) ARGUMENTs="$ARGUMENTs $2"; shift;; + (--) shift; break;; + (-*) break;; + (*) break;; + esac + shift + done + if [[ ${#ADDRESS} -gt 0 ]]; then SSHOPTs="-o StrictHostKeyChecking=no" - if [[ $# -eq 2 ]]; then - if ! timeout $1 sshpass -p "$(password)" ssh $SSHOPTs "$(username)@$ADDRESS" "$2"; then + if [[ ${#TIMEOUT} -ne 0 ]]; then + if ! timeout $TIMEOUT sshpass -p "$(password)" ssh $ARGUMENTs $SSHOPTs "$(username)@$ADDRESS" "$@"; then return -2 fi - elif ! sshpass -p "$(password)" ssh $SSHOPTs "$(username)@$ADDRESS" "$1"; then + elif ! sshpass -p "$(password)" ssh $ARGUMENTs $SSHOPTs "$(username)@$ADDRESS" "$@"; then + return -2 + fi + else + return -3 + fi +} + +function exec_on_test_machine_without_output() { + if [[ ${#MACHINE} -gt 0 ]]; then + source $ROOT/tests/pipeline/environments/$MACHINE + else + return -1 + fi + + while [ $# -gt 0 ]; do + case $1 in + --timeout) TIMEOUT="$2"; shift;; + --add-arg) ARGUMENTs="$ARGUMENTs $2"; shift;; + (--) shift; break;; + (-*) break;; + (*) break;; + esac + shift + done + + if [[ ${#ADDRESS} -gt 0 ]]; then + SSHOPTs="-o StrictHostKeyChecking=no" + + if [[ ${#TIMEOUT} -ne 0 ]]; then + if ! timeout $TIMEOUT sshpass -p "$(password)" ssh $ARGUMENTs $SSHOPTs "$(username)@$ADDRESS" "$@" &> /dev/null; then + return -2 + fi + elif ! sshpass -p "$(password)" ssh $ARGUMENTs $SSHOPTs "$(username)@$ADDRESS" "$@" &> /dev/null; then return -2 fi else @@ -64,3 +127,4 @@ function install_package_to_test_machine() { return -3 fi } + diff --git a/tests/pipeline/test.sh b/tests/pipeline/test.sh index 78b50e972..64a537cd2 100755 --- a/tests/pipeline/test.sh +++ b/tests/pipeline/test.sh @@ -6,6 +6,7 @@ ROOT="$(git rev-parse --show-toplevel)" source $PIPELINE/libraries/Logcat.sh source $PIPELINE/libraries/Package.sh +source $PIPELINE/libraries/Console.sh SCRIPT="$(basename "$0")" @@ -82,22 +83,50 @@ for DISTRO in $(ls -1c $ROOT/tests/pipeline/environments); do IDX=$((IDX+1)) AVAILABLE=0 + BUILDER="/home/$(username)/ibus-unikey/Base/Tools/Builder/build" for I in {0..50}; do + export MACHINE="$DISTRO" + export ADDRESS="192.168.100.2" + if ! sshpass -p "rootroot" ssh $SSHOPTs root@192.168.100.2 -tt exit 0 &> /dev/null; then sleep 10 - elif ! sshpass -p "rootroot" ssh $SSHOPTs root@192.168.100.2 -tt "echo '$(username):$(password)' | chpasswd"; then - error "can't change password account $(username)" - elif ! sshpass -p "$(password)" ssh $SSHOPTs $(username)@192.168.100.2 -tt exit 0; then - error "it seems $(username)'s password is set wrong" - elif ! is_fully_started "192.168.100.2"; then + continue + elif [ -d $ROOT/build ]; then + rm -fr $ROOT/build + + if ! sshpass -p "rootroot" ssh $SSHOPTs root@192.168.100.2 -tt "echo '$(username):$(password)' | chpasswd" &> /dev/null; then + error "can't change password account $(username)" + elif ! sshpass -p "$(password)" ssh $SSHOPTs $(username)@192.168.100.2 -tt exit 0 &> /dev/null; then + error "it seems $(username)'s password is set wrong" + elif ! rsync_to_test_machine $ROOT --exclude={'pxeboot','vms'}; then + error "can't rsync $ROOT to /home/$(username)/ibus-unikey" + elif exec_on_test_machine_without_output "mkdir /home/$(username)/ibus-unikey/build"; then + if ! exec_on_test_machine "cd ~/ibus-unikey && BUILD='-DCMAKE_INSTALL_PREFIX=/usr' $BUILDER --root /home/$(username)/ibus-unikey --rebuild 0 --mode 1"; then + error "can't build ibus-unikey with machine $MACHINE" + fi + fi + fi + + if ! is_fully_started "192.168.100.2"; then sleep 10 else AVAILABLE=1 + CURRENT=$(pwd) info "machine $DISTRO is available now, going to test our test suites" + + if exec_on_test_machine 'loginctl session-status 1 | grep Service: | grep wayland'; then + export DISPLAY="WAYLAND_DISPLAY=wayland-0 DISPLAY=:0" + + warning "machine $MACHINE is using wayland" + else + export DISPLAY="DISPLAY=:0" + fi for ITEM in $(ls -1c $ROOT/tests); do + cd $CURRENT + if [ $ITEM = "pipeline" ]; then continue elif [ ! -d $ROOT/tests/$ITEM ]; then @@ -105,13 +134,29 @@ for DISTRO in $(ls -1c $ROOT/tests/pipeline/environments); do elif [ ! -d $ROOT/tests/$ITEM/steps ]; then continue fi - + export SUITE="$ROOT/tests/$ITEM" - export MACHINE="$DISTRO" - export ADDRESS="192.168.100.2" for STEP in $(ls -1c $SUITE/steps | sort); do - . $SUITE/steps/$STEP + EXT="${STEP##*.}" + + warning """starting $STEP of suite $(basename $SUITE)" + + if [ $EXT = 'sh' ]; then + . $SUITE/steps/$STEP + else + echo """------------------------------------------------------------------------------- +""" + if ! copy_to_test_machine $SUITE/steps/$STEP; then + error "fail to copy $STEP to $MACHINE" + elif ! exec_on_test_machine "$DISPLAY ~/$STEP"; then + error "fail at step $STEP" + fi + + echo "-------------------------------------------------------------------------------" + fi + + info "Done $STEP of suite $(basename $SUITE)" done done break