diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..88ac3066 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +_build +archlinux +dist diff --git a/.gitignore b/.gitignore index 76de788b..26f66d4a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tmp /*.geany *.out /_build +/dist diff --git a/.travis.yml b/.travis.yml index eb187f2e..4cb97d3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,70 +3,15 @@ dist: xenial sudo: required language: python -python: 2.7 +python: 3.7 -env: -- MAX_CPU_PERCENT=20 MAX_MEM_PERCENT=5 +services: +- docker install: - sudo apt-key update - sudo apt-get -yq update -- sudo apt -yq install xvfb gnome-shell - -# Install NodeJS from upstream, since the version that comes with Ubuntu 14 is ancient. -# https://askubuntu.com/a/548776/13217 -- sudo apt-get -yq install curl -- curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - -- sudo apt-get install -yq nodejs - -# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package. -- sudo bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true" -- which nodejs -- which node - -# Install NPM from upstream. -- git clone git://github.com/npm/cli.git -- cd cli/scripts -- chmod +x install.sh -- sudo ./install.sh -- cd ../.. - -- sudo npm install -g eslint - -before_script: - - "export DISPLAY=:99.0" - - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16" - - sleep 3 # give xvfb some time to start - - sudo gnome-shell & - - sleep 3 # give gnome-shell some time to start script: - -# Clear initial gnome-shell errors we don't care about. -- sudo journalctl /usr/bin/gnome-shell -- sudo journalctl --rotate -- sudo journalctl --vacuum-time=1s - -# Show pre-extension gnome-shell performance. -- ps -C gnome-shell -o %cpu,%mem,cmd - -# Run JSlint check. -- cd $TRAVIS_BUILD_DIR -- ./checkjs.sh - -# Install and enable extension. -- sudo make install -- gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com - -# Give extension time to run. -- sleep 10 - -# Show post-extension gnome-shell performance. -- ps -C gnome-shell -o %cpu,%mem,cmd -# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%. -- bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]' -# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%. -- bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]' -# Confirm extension hasn't thrown any errors. -- sudo journalctl /usr/bin/gnome-shell -- sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-" +- ./run_docker_tests.sh ubuntu1804 +- ./run_docker_tests.sh ubuntu2004 diff --git a/Dockerfile.ubuntu1804 b/Dockerfile.ubuntu1804 new file mode 100644 index 00000000..c0c9f92a --- /dev/null +++ b/Dockerfile.ubuntu1804 @@ -0,0 +1,48 @@ +FROM ubuntu:18.04 +ENV PYTHONUNBUFFERED 1 + +USER root +ENV HOME /home/root + +# Install sudo. Not strictly required inside Docker, but it will allow Docker to run scripts that typically run outside Docker +# which do use sudo. +RUN apt update && apt -yq install sudo +RUN sudo echo "hi" + +# Setup localization. +ENV DEBIAN_FRONTEND noninteractive +RUN apt update +RUN apt install -y locales +RUN rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +RUN apt update +ENV LANG en_US.utf8 + +# Install dependencies +RUN apt-get -yq update && apt-get install -y gnupg2 +RUN apt-key update +RUN apt-get -yq update +RUN apt-get -yq install xvfb gnome-shell git make bc dbus procps + +# Install NodeJS from upstream, since the version that comes with the distro is ancient. +# https://askubuntu.com/a/548776/13217 +RUN apt-get -yq install curl +RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - +RUN apt-get install -yq nodejs + +# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package. +RUN bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true" +RUN which nodejs +RUN which node + +# Install NPM from upstream. +RUN git clone git://github.com/npm/cli.git +RUN cd cli/scripts; chmod +x install.sh; ./install.sh +RUN npm install -g eslint + +# Install code. +RUN mkdir -p /home/root/git/gnome-shell-system-monitor-applet +COPY . /home/root/git/gnome-shell-system-monitor-applet +WORKDIR /home/root/git/gnome-shell-system-monitor-applet + +# Run test wrapper. +CMD ./docker_cmd_ubuntu1804.sh diff --git a/Dockerfile.ubuntu2004 b/Dockerfile.ubuntu2004 new file mode 100644 index 00000000..f3ac8767 --- /dev/null +++ b/Dockerfile.ubuntu2004 @@ -0,0 +1,47 @@ +FROM ubuntu:20.04 +ENV PYTHONUNBUFFERED 1 + +USER root + +# Install sudo. Not strictly required inside Docker, but it will allow Docker to run scripts that typically run outside Docker +# which do use sudo. +RUN apt update && apt -yq install sudo +RUN sudo echo "hi" + +# Setup localization. +ENV DEBIAN_FRONTEND noninteractive +RUN apt update +RUN apt install -y locales +RUN rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +RUN apt update +ENV LANG en_US.utf8 + +# Install dependencies +RUN apt-get -yq update && apt-get install -y gnupg2 +RUN apt-key update +RUN apt-get -yq update +RUN apt-get -yq install xvfb gnome-shell git make bc dbus + +# Install NodeJS from upstream, since the version that comes with the distro is ancient. +# https://askubuntu.com/a/548776/13217 +RUN apt-get -yq install curl +RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - +RUN apt-get install -yq nodejs + +# Necessary on some versions of Ubuntu 14, which has a malformed npm/nodejs package. +RUN bash -c "[ ! -f /usr/bin/node ] && ln -s /usr/bin/nodejs /usr/bin/node || true" +RUN which nodejs +RUN which node + +# Install NPM from upstream. +RUN git clone git://github.com/npm/cli.git +RUN cd cli/scripts; chmod +x install.sh; ./install.sh +RUN npm install -g eslint + +# Install code. +RUN mkdir -p /home/root/git/gnome-shell-system-monitor-applet +COPY . /home/root/git/gnome-shell-system-monitor-applet +WORKDIR /home/root/git/gnome-shell-system-monitor-applet + +# Run test wrapper. +CMD ./docker_cmd_ubuntu2004.sh diff --git a/checkjs.sh b/checkjs.sh index 85662761..3b578df7 100755 --- a/checkjs.sh +++ b/checkjs.sh @@ -1,4 +1,5 @@ #!/bin/bash # Install eslint with: # sudo apt-get install npm && sudo npm install -g eslint +set -e eslint system-monitor@paradoxxx.zero.gmail.com diff --git a/docker-compose.ubuntu1804.yml b/docker-compose.ubuntu1804.yml new file mode 100644 index 00000000..c16246ec --- /dev/null +++ b/docker-compose.ubuntu1804.yml @@ -0,0 +1,12 @@ +#https://docs.docker.com/compose/compose-file/#shm_size +version: "3.5" +services: + + test: + build: + context: . + # Increase the size of shared memory. + # The default shared memory is only 64mb, causing odd Selenium errors like: + # selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette + shm_size: '1gb' + dockerfile: Dockerfile.ubuntu1804 diff --git a/docker-compose.ubuntu2004.yml b/docker-compose.ubuntu2004.yml new file mode 100644 index 00000000..26425883 --- /dev/null +++ b/docker-compose.ubuntu2004.yml @@ -0,0 +1,12 @@ +#https://docs.docker.com/compose/compose-file/#shm_size +version: "3.5" +services: + + test: + build: + context: . + # Increase the size of shared memory. + # The default shared memory is only 64mb, causing odd Selenium errors like: + # selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette + shm_size: '1gb' + dockerfile: Dockerfile.ubuntu2004 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..494a0400 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +#https://docs.docker.com/compose/compose-file/#shm_size +version: "3.5" +services: + test: + build: + context: . + # Increase the size of shared memory. + # The default shared memory is only 64mb, causing odd Selenium errors like: + # selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette + shm_size: '1gb' + dockerfile: Dockerfile.${DISTRO} diff --git a/docker_cmd_ubuntu1804.sh b/docker_cmd_ubuntu1804.sh new file mode 100755 index 00000000..46935068 --- /dev/null +++ b/docker_cmd_ubuntu1804.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Called from the Dockerfile.* to execute our tests via the CMD. +set -e + +echo "[$(date)] Launching Dbus." +mkdir -p /var/run/dbus +dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address +sleep 3 # give Dbus some time to start + +echo "[$(date)] Launching Xvfb." +export DISPLAY=:99.0 +/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16 +sleep 3 # give xvfb some time to start + +echo "[$(date)] Launching Gnome-Shell." +sudo gnome-shell & +sleep 3 # give gnome-shell some time to start +echo "[$(date)] Confirming Gnome-Shell is running." +pgrep gnome-shell + +echo "[$(date)] Showing Gnome-Shell log entries." +sudo journalctl /usr/bin/gnome-shell || true +echo "[$(date)] Rotating Gnome-Shell log entries." +sudo journalctl --rotate || true +echo "[$(date)] Clearing Gnome-Shell log entries." +sudo journalctl --vacuum-time=1s || true + +echo "[$(date)] Show pre-extension Gnome-Shell performance." +ps -C gnome-shell -o %cpu,%mem,cmd || true + +echo "[$(date)] Running JSLint check." +#cd $TRAVIS_BUILD_DIR +./checkjs.sh + +echo "[$(date)] Installing extension." +sudo make install +gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com +sleep 10 # Give extension time to run. + +echo "[$(date)] Showing post-extension Gnome-Shell performance." +export MAX_CPU_PERCENT=20 +export MAX_MEM_PERCENT=5 +ps -C gnome-shell -o %cpu,%mem,cmd +# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%. +bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]' +# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%. +bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]' + +echo "[$(date)] Confirming extension hasn't thrown any errors." +# Note, finding no entries returns an error code of 1, which in our case means no error. +sudo journalctl /usr/bin/gnome-shell +sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-" +sudo journalctl --since=$(date '+%Y-%m-%d') /usr/bin/gnome-shell|grep -i "Extension \"system-monitor@paradoxxx.zero.gmail.com\" had error" diff --git a/docker_cmd_ubuntu2004.sh b/docker_cmd_ubuntu2004.sh new file mode 100755 index 00000000..2e99dc64 --- /dev/null +++ b/docker_cmd_ubuntu2004.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Called from the Dockerfile.* to execute our tests via the CMD. +set -e + +echo "[$(date)] Launching Dbus." +mkdir -p /var/run/dbus +dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address +sleep 3 # give Dbus some time to start + +echo "[$(date)] Launching Xvfb." +export DISPLAY=:99.0 +/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16 +sleep 3 # give xvfb some time to start + +echo "[$(date)] Launching Gnome-Shell." +sudo gnome-shell & +sleep 3 # give gnome-shell some time to start + +echo "[$(date)] Clearing Gnome-Shell log entries." +sudo journalctl /usr/bin/gnome-shell || true +sudo journalctl --rotate +sudo journalctl --vacuum-time=1s + +echo "[$(date)] Show pre-extension Gnome-Shell performance." +ps -C gnome-shell -o %cpu,%mem,cmd + +echo "[$(date)] Running JSLint check." +#cd $TRAVIS_BUILD_DIR +./checkjs.sh + +echo "[$(date)] Installing extension." +sudo make install +gnome-shell-extension-tool --enable-extension=system-monitor@paradoxxx.zero.gmail.com +sleep 10 # Give extension time to run. + +echo "[$(date)] Showing post-extension Gnome-Shell performance." +export MAX_CPU_PERCENT=20 +export MAX_MEM_PERCENT=5 +ps -C gnome-shell -o %cpu,%mem,cmd +# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%. +bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]' +# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%. +bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]' + +echo "[$(date)] Confirming extension hasn't thrown any errors." +# Note, finding no entries returns an error code of 1, which in our case means no error. +sudo journalctl /usr/bin/gnome-shell +sudo journalctl /usr/bin/gnome-shell|grep "\-\- No entries \-\-" +sudo journalctl --since=$(date '+%Y-%m-%d') /usr/bin/gnome-shell|grep -i "Extension \"system-monitor@paradoxxx.zero.gmail.com\" had error" diff --git a/run_docker_tests.sh b/run_docker_tests.sh new file mode 100755 index 00000000..070e0090 --- /dev/null +++ b/run_docker_tests.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# The top-level user script for executing tests from Docker. +# The first argument should be a distro identifier. + +export DISTRO=${1:-ubuntu1804} + +echo "[$(date)] Running $DISTRO tests." + +COMPOSE_FILE_LOC="docker-compose.yml" + +# This must match the name in the docker-compose.*.yml file. +TEST_CONTAINER_NAME="test" + +COMPOSE_PROJECT_NAME_ORIGINAL="test_${BUILD_TAG}" +echo "[$(date)] COMPOSE_PROJECT_NAME_ORIGINAL=$COMPOSE_PROJECT_NAME_ORIGINAL" + +# Project name is sanitized by Compose, so we need to do the same thing. +# See https://github.com/docker/compose/issues/2119. +COMPOSE_PROJECT_NAME=$(echo $COMPOSE_PROJECT_NAME_ORIGINAL | awk '{print tolower($0)}' | sed 's/[^a-z0-9]*//g') +echo "[$(date)] COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME" +TEST_CONTAINER_REF="${COMPOSE_PROJECT_NAME}_${TEST_CONTAINER_NAME}_1" +echo "[$(date)] TEST_CONTAINER_REF=$TEST_CONTAINER_REF" + +# Record installed version of Docker and Compose with each build +echo "[$(date)] Docker environment:" +docker --version +docker-compose --version + +function cleanup { + echo "[$(date)] Shutting down..." + docker-compose -f $COMPOSE_FILE_LOC -p $COMPOSE_PROJECT_NAME down --remove-orphans + echo "[$(date)] Stopping..." + docker ps -a --no-trunc | grep $COMPOSE_PROJECT_NAME | awk '{print $1}' | xargs --no-run-if-empty docker stop + echo "[$(date)] Removing..." + docker ps -a --no-trunc | grep $COMPOSE_PROJECT_NAME | awk '{print $1}' | xargs --no-run-if-empty docker rm + echo "[$(date)] Delete old containers." + docker system prune -a -f +} + +function run_tests { + echo "[$(date)] Creating containers..." + docker-compose -f $COMPOSE_FILE_LOC -p $COMPOSE_PROJECT_NAME up --build --force-recreate --exit-code-from test + ret_code=$? + echo "[$(date)] Docker Compose exit code: $ret_code" + + # List images and containers related to this build + docker images | grep $COMPOSE_PROJECT_NAME | awk '{print $0}' + docker ps -a | grep $COMPOSE_PROJECT_NAME | awk '{print $0}' + + # Follow the container with tests... + docker logs -f $TEST_CONTAINER_REF + + exit $ret_code +} + +set -e +cleanup # Initial cleanup. +trap cleanup EXIT # Cleanup after tests finish running + +run_tests diff --git a/system-monitor@paradoxxx.zero.gmail.com/extension.js b/system-monitor@paradoxxx.zero.gmail.com/extension.js index 9bdfea8b..37b246a1 100644 --- a/system-monitor@paradoxxx.zero.gmail.com/extension.js +++ b/system-monitor@paradoxxx.zero.gmail.com/extension.js @@ -49,7 +49,7 @@ var Me = ExtensionUtils.getCurrentExtension(); var Convenience = Me.imports.convenience; var Compat = Me.imports.compat; -var Background, GTop, IconSize, Locale, MountsMonitor, NM, NetworkManager, Schema, StatusArea, Style, gc_timeout, menu_timeout; +var Background, GTop, IconSize, Locale, MountsMonitor, NM, NetworkManager, Schema, StatusArea, Style, TipItem, gc_timeout, menu_timeout; try { GTop = imports.gi.GTop; @@ -661,10 +661,8 @@ const Pie = class SystemMonitor_Pie extends Graph { } } -var TipItem = null; - if (shell_Version < '3.36') { - var TipItem = class SystemMonitor_TipItem extends PopupMenu.PopupBaseMenuItem { + TipItem = class SystemMonitor_TipItem extends PopupMenu.PopupBaseMenuItem { constructor() { super(); // PopupMenu.PopupBaseMenuItem.prototype._init.call(this); @@ -673,11 +671,11 @@ if (shell_Version < '3.36') { } } } else { - var TipItem = GObject.registerClass( + TipItem = GObject.registerClass( { GTypeName: 'TipItem' }, - class TipItem extends PopupMenu.PopupBaseMenuItem { + class SystemMonitor_TipItem extends PopupMenu.PopupBaseMenuItem { _init() { super._init(); // PopupMenu.PopupBaseMenuItem.prototype._init.call(this); @@ -687,6 +685,7 @@ if (shell_Version < '3.36') { } ); } + const TipMenu = class SystemMonitor_TipMenu extends PopupMenu.PopupMenuBase { constructor(sourceActor) { // PopupMenu.PopupMenuBase.prototype._init.call(this, sourceActor, 'sm-tooltip-box');