#!/usr/bin/perl

use v5.16;
use strict;
use warnings;
use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);

my $show_help;
GetOptions (
  'help' => \$show_help,
) or die("Error in command line arguments\n");

my $VERSION = "0.1.0";
my $help = "Usage: run-tests [options]
--help   \tShow this help message
";

if($show_help) {
  print("$help");
  exit
}

my @pkgs = qw(
  libhipblas3-tests
  libhipcub-tests
  libhipfft0-tests
  libhiprand1-tests
  libhipsolver1-tests
  libhipsparse4-tests
  libmiopen1-tests
  librccl1-tests
  librocblas5-tests
  librocfft0-tests
  librocprim-tests
  librocrand1-tests
  librocsolver0-tests
  librocsparse1-tests
  librocthrust-tests
  libhsa-runtime64-tests
);

my $result = 0;
foreach my $pkg (@pkgs) {
  my $test = "/usr/libexec/rocm/$pkg/run-tests";
  if (-x $test) {
    my $options = '';
    print("--- Starting $pkg ---\n");
    my $status = system("$test$options");
    my $msg = ($status == 0) ? 'PASS' : 'FAIL';
    print("--- Finished $pkg: $msg ---\n");
    $result += $status;
  } else {
    warn("WARNING: Skipping $pkg - test binary not found at $test\n");
  }
}
exit $result;
