commit:     27f35b8a59b2afcc090c5e576a69ad7f1eb14b12
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 27 12:46:06 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Oct 27 12:46:06 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=27f35b8a

qlop: allow forcing non-proc running mode using -rr for testing

Adapt test to use -rr to force falling back to scanning emerge.log, and
give -d to the data range in which things happen, such that the 10-day
cutoff can be calculated based on that for deterministic output.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 qlop.c                 | 25 ++++++++++++++-----------
 tests/qlop/dotest      |  4 ++--
 tests/qlop/list10.good |  6 +++---
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/qlop.c b/qlop.c
index 6cb2c04..7083ea7 100644
--- a/qlop.c
+++ b/qlop.c
@@ -344,7 +344,6 @@ New format:
 1550953125:  *** exiting successfully.
 1550953125:  *** terminating.
 
-
 Currently running merges can be found in the /proc filesystem:
 - Linux: readlink(/proc/<pid>/fd/X)
 - Solaris: readlink(/proc/<pid>/path/X)
@@ -846,16 +845,18 @@ static int do_emerge_log(
        if (flags->do_running) {
                time_t cutofftime;
 
+               tstart = time(NULL);
+
                /* emerge.log can be interrupted, incorrect and hopelessly lost,
                 * so to eliminate some unfinished crap from there, we just
                 * ignore anything that's > cutofftime, 10 days for now. */
                cutofftime = 10 * 24 * 60 * 60;  /* when we consider entries 
stale */
+               cutofftime = (tbegin > 0 ? tbegin : tstart) - cutofftime;
 
                /* can't report endtime for non-finished operations */
                flags->do_endtime = 0;
-               tstart = time(NULL);
                sync_time /= sync_cnt;
-               if (sync_start >= tstart - cutofftime) {
+               if (sync_start >= cutofftime) {
                        elapsed = tstart - sync_start;
                        if (elapsed >= sync_time)
                                sync_time = 0;
@@ -878,7 +879,7 @@ static int do_emerge_log(
                        time_t maxtime = 0;
                        bool isMax = false;
 
-                       if (pkgw->tbegin < tstart - cutofftime)
+                       if (pkgw->tbegin < cutofftime)
                                continue;
 
                        snprintf(afmt, sizeof(afmt), "%s/%s",
@@ -925,7 +926,7 @@ static int do_emerge_log(
                        time_t maxtime = 0;
                        bool isMax = false;
 
-                       if (pkgw->tbegin < tstart - cutofftime)
+                       if (pkgw->tbegin < cutofftime)
                                continue;
 
                        snprintf(afmt, sizeof(afmt), "%s/%s",
@@ -1140,6 +1141,7 @@ int qlop_main(int argc, char **argv)
        char *q;
        depend_atom *atom;
        DECLARE_ARRAY(atoms);
+       int runningmode = 0;
 
        start_time = 0;
        end_time = LONG_MAX;
@@ -1173,7 +1175,8 @@ int qlop_main(int argc, char **argv)
                                          m.show_lastmerge = 1;
                                          m.show_emerge = 1;
                                          verbose = 1;          break;
-                       case 'r': m.do_running = 1;     break;
+                       case 'r': m.do_running = 1;
+                                         runningmode++;        break;
                        case 'a': m.do_average = 1;     break;
                        case 'c': m.do_summary = 1;     break;
                        case 'H': m.do_human = 1;       break;
@@ -1312,14 +1315,14 @@ int qlop_main(int argc, char **argv)
        if (m.do_running) {
                array_t *new_atoms = probe_proc(atoms);
 
-               if (new_atoms != NULL && array_cnt(new_atoms) == 0) {
-                       /* proc supported, found nothing running */
-                       start_time = LONG_MAX;
-               } else {
+               if (runningmode > 1 || new_atoms == NULL) {
                        warn("/proc not available, deducing running "
                                        "merges from emerge.log");
+               } else if (array_cnt(new_atoms) == 0) {
+                       /* proc supported, found nothing running */
+                       start_time = LONG_MAX;
                }
-
+               /* NOTE: new_atoms == atoms when new_atoms != NULL */
        }
 
        if (start_time < LONG_MAX)

diff --git a/tests/qlop/dotest b/tests/qlop/dotest
index bf5edc0..321f7d2 100755
--- a/tests/qlop/dotest
+++ b/tests/qlop/dotest
@@ -10,7 +10,7 @@ test() {
        local num=$1 exp=$2 ret=0
        shift 2
        eval "$@" > list || ret=$?
-       if ! diff -u list ${as}/list${num}.good ; then
+       if ! diff -u ${as}/list${num}.good list ; then
                tfail "output does not match"
        fi
        if [[ ${exp} -ne ${ret} ]] ; then
@@ -48,7 +48,7 @@ test 09 0 "qlop -Hacv automake -f ${as}/aborts.log"
 
 # https://bugs.gentoo.org/697068: a parallel emerge finishing should
 # wipe the outstanding emerges from other emerges
-test 10 0 "qlop -r -f ${as}/parallel.log"
+test 10 0 "qlop -Mrr -f ${as}/parallel.log" -d 1568976528
 
 cleantmpdir
 

diff --git a/tests/qlop/list10.good b/tests/qlop/list10.good
index 845573f..348992a 100644
--- a/tests/qlop/list10.good
+++ b/tests/qlop/list10.good
@@ -1,3 +1,3 @@
-2019-09-20T12:27:40 >>> dev-qt/qtmultimedia... (96 of 129) ETA: unknown
-2019-09-20T16:17:50 >>> kde-frameworks/kxmlgui... (98 of 129) ETA: unknown
-2019-09-20T16:18:28 >>> net-analyzer/wireshark... (99 of 129) ETA: unknown
+1568982460 >>> dev-qt/qtmultimedia... (96 of 129) ETA: unknown
+1568996270 >>> kde-frameworks/kxmlgui... (98 of 129) ETA: unknown
+1568996308 >>> net-analyzer/wireshark... (99 of 129) ETA: unknown

Reply via email to