#!/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(
  libhipblas0-tests
  libhipcub-tests
  libhipfft0-tests
  libhiprand1-tests
  libhipsolver0-tests
  libhipsparse0-tests
  libmiopen1-tests
  librccl1-tests
  librocblas0-tests
  librocfft0-tests
  librocprim-tests
  librocrand1-tests
  librocsolver0-tests
  librocsparse0-tests
  librocthrust-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;
  }
}
exit $result;
