From 8ecb0ad0c4b56ff177ca6cfdef3c16c07950b55d Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Thu, 3 Oct 2024 10:00:09 +0800 Subject: [PATCH] root: fixed CI error when operating on incompatible machine It appears the CI produced some errors when GitHub uses darwin-arm64 instead of darwin-amd64 mac machine and the test suite could not operate properly. Hence, let's fix it. This patch fixes the CI error when operating on an incompatible machine in root repository. Co-authored-by: Shuralyov, Jean Co-authored-by: Galyna, Cory Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- init/services/compilers/upscaler.ps1 | 830 +++++++++++----------- tests/01_test_upscale_image_single.sh.ps1 | 117 +-- 2 files changed, 485 insertions(+), 462 deletions(-) diff --git a/init/services/compilers/upscaler.ps1 b/init/services/compilers/upscaler.ps1 index 21d94c8..704b42d 100644 --- a/init/services/compilers/upscaler.ps1 +++ b/init/services/compilers/upscaler.ps1 @@ -36,520 +36,528 @@ function UPSCALER-Batch-Load { - param( - [string]$___video, - [string]$___model, - [string]$___scale, - [string]$___format, - [string]$___parallel, - [string]$___gpu, - [string]$___input, - [string]$___output - ) - - - # validate input - if ( ((STRINGS-Is-Empty "${___video}") -eq 0) -or - ((STRINGS-Is-Empty "${___model}") -eq 0) -or - ((STRINGS-Is-Empty "${___scale}") -eq 0) -or - ((STRINGS-Is-Empty "${___format}") -eq 0) -or - ((STRINGS-Is-Empty "${___parallel}") -eq 0) -or - ((STRINGS-Is-Empty "${___gpu}") -eq 0) -or - ((STRINGS-Is-Empty "${___input}") -eq 0) -or - ((STRINGS-Is-Empty "${___output}") -eq 0)) { - return 1 - } - - - if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { - return 1 - } - - - # report status - return 0 + param ( + [string]$___video, + [string]$___model, + [string]$___scale, + [string]$___format, + [string]$___parallel, + [string]$___gpu, + [string]$___input, + [string]$___output + ) + + + # validate input + if ( + ((STRINGS-Is-Empty $___video) -eq 0) -or + ((STRINGS-Is-Empty $___model) -eq 0) -or + ((STRINGS-Is-Empty $___scale) -eq 0) -or + ((STRINGS-Is-Empty $___format) -eq 0) -or + ((STRINGS-Is-Empty $___parallel) -eq 0) -or + ((STRINGS-Is-Empty $___gpu) -eq 0) -or + ((STRINGS-Is-Empty $___input) -eq 0) -or + ((STRINGS-Is-Empty $___output) -eq 0) + ) { + return 1 + } + + + if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { + return 1 + } + + + # report status + return 0 } function UPSCALER-Batch-Run { - param( - [string]$___video, - [string]$___model, - [string]$___scale, - [string]$___format, - [string]$___parallel, - [string]$___gpu, - [string]$___input, - [string]$___output - ) - - - # validate input - if ( ((STRINGS-Is-Empty "${___video}") -eq 0) -or - ((STRINGS-Is-Empty "${___model}") -eq 0) -or - ((STRINGS-Is-Empty "${___scale}") -eq 0) -or - ((STRINGS-Is-Empty "${___format}") -eq 0) -or - ((STRINGS-Is-Empty "${___parallel}") -eq 0) -or - ((STRINGS-Is-Empty "${___gpu}") -eq 0) -or - ((STRINGS-Is-Empty "${___input}") -eq 0) -or - ((STRINGS-Is-Empty "${___output}") -eq 0)) { - return 1 - } - - - # execute - if ((STRINGS-Is-Empty "${env:UPSCALER_TEST_MODE}") -ne 0) { - $null = I18N-Report-Simulation "$(UPSCALER-Program-Get) ${___cmd}" - $null = FS-Make-Housing-Directory "${___output}" - $null = FS-Remove-Silently "${___output}" - $___process = FS-Copy-File "${___input}" "${___output}" - if ($___process -eq 0) { - return 0 - } - } - - - # report status - return 0 + param ( + [string]$___video, + [string]$___model, + [string]$___scale, + [string]$___format, + [string]$___parallel, + [string]$___gpu, + [string]$___input, + [string]$___output + ) + + + # validate input + if ( + ((STRINGS-Is-Empty $___video) -eq 0) -or + ((STRINGS-Is-Empty $___model) -eq 0) -or + ((STRINGS-Is-Empty $___scale) -eq 0) -or + ((STRINGS-Is-Empty $___format) -eq 0) -or + ((STRINGS-Is-Empty $___parallel) -eq 0) -or + ((STRINGS-Is-Empty $___gpu) -eq 0) -or + ((STRINGS-Is-Empty $___input) -eq 0) -or + ((STRINGS-Is-Empty $___output) -eq 0) + ) { + return 1 + } + + + # execute + if ((STRINGS-Is-Empty ${env:UPSCALER_TEST_MODE}) -ne 0) { + $null = I18N-Report-Simulation "$(UPSCALER-Program-Get) ${___cmd}" + $null = FS-Make-Housing-Directory "${___output}" + $null = FS-Remove-Silently "${___output}" + $___process = FS-Copy-File "${___input}" "${___output}" + if ($___process -eq 0) { + return 0 + } + } + + + # report status + return 0 } function UPSCALER-Batch-Setup { - param( - [string]$___video, - [string]$___model, - [string]$___scale, - [string]$___format, - [string]$___parallel, - [string]$___gpu, - [string]$___input, - [string]$___output - ) - - - # validate input - if ( ((STRINGS-Is-Empty "${___video}") -eq 0) -or - ((STRINGS-Is-Empty "${___model}") -eq 0) -or - ((STRINGS-Is-Empty "${___scale}") -eq 0) -or - ((STRINGS-Is-Empty "${___format}") -eq 0) -or - ((STRINGS-Is-Empty "${___parallel}") -eq 0) -or - ((STRINGS-Is-Empty "${___gpu}") -eq 0) -or - ((STRINGS-Is-Empty "${___input}") -eq 0) -or - ((STRINGS-Is-Empty "${___output}") -eq 0)) { - return 1 - } - - - if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { - return 1 - } - - - # report status - return 0 + param ( + [string]$___video, + [string]$___model, + [string]$___scale, + [string]$___format, + [string]$___parallel, + [string]$___gpu, + [string]$___input, + [string]$___output + ) + + + # validate input + if ( + ((STRINGS-Is-Empty $___video) -eq 0) -or + ((STRINGS-Is-Empty $___model) -eq 0) -or + ((STRINGS-Is-Empty $___scale) -eq 0) -or + ((STRINGS-Is-Empty $___format) -eq 0) -or + ((STRINGS-Is-Empty $___parallel) -eq 0) -or + ((STRINGS-Is-Empty $___gpu) -eq 0) -or + ((STRINGS-Is-Empty $___input) -eq 0) -or + ((STRINGS-Is-Empty $___output) -eq 0) + ) { + return 1 + } + + + if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { + return 1 + } + + + # report status + return 0 } function UPSCALER-Format-Validate { - param( - [string]$___format - ) - - - # valdiate input - if ((STRINGS-Is-Empty "${___format}") -eq 0) { - return "" - } - - - # execute - switch ($(STRINGS-To-Lowercase "${___format}")) { - { $_ -in "jpeg", "jpg" } { - return "jpg" - } "png" { - return "png" - } "webp" { - return "webp" - } "native" { - return "native" - } default { - return "" - }} + param ( + [string]$___format + ) + + + # valdiate input + if ((STRINGS-Is-Empty $___format) -eq 0) { + return "" + } + + + # execute + switch ($(STRINGS-To-Lowercase $___format)) { + { $_ -in "jpeg", "jpg" } { + return "jpg" + } "png" { + return "png" + } "webp" { + return "webp" + } "native" { + return "native" + } default { + return "" + }} } function UPSCALER-Output-Filename-Image { - param( - [string]$___output, - [string]$___input, - [string]$___format - ) - - - # validate input - if ((STRINGS-IS-Empty "${___output}") -ne 0) { - return "${___output}" - } - - if ((STRINGS-IS-Empty "${___input}") -eq 0) { - return "" - } - - - # execute - $___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}")" "*" - if ($(Split-Path -Parent -Path "${___input}") -ne "${___input}") { - $___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled" - } else { - $___output = ".\${___output}-upscaled" - } - - switch ($___format) { - "jpg" { - $___output = "${___output}.jpg" - } "webp" { - $___output = "${___output}.webp" - } default { - $___output = "${___output}.png" - }} - - return $___output + param( + [string]$___output, + [string]$___input, + [string]$___format + ) + + + # validate input + if ((STRINGS-IS-Empty $___output) -ne 0) { + return $___output + } + + if ((STRINGS-IS-Empty $___input) -eq 0) { + return "" + } + + + # execute + $___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}")" "*" + if ($(Split-Path -Parent -Path $___input) -ne $___input) { + $___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled" + } else { + $___output = ".\${___output}-upscaled" + } + + switch ($___format) { + "jpg" { + $___output = "${___output}.jpg" + } "webp" { + $___output = "${___output}.webp" + } default { + $___output = "${___output}.png" + }} + + return $___output } function UPSCALER-Output-Filename-Video { - param( - [string]$___output, - [string]$___input - ) + param( + [string]$___output, + [string]$___input + ) - # validate input - if ((STRINGS-IS-Empty "${___output}") -ne 0) { - return "${___output}" - } + # validate input + if ((STRINGS-IS-Empty $___output) -ne 0) { + return "${___output}" + } - if ((STRINGS-IS-Empty "${___input}") -eq 0) { - return "" - } + if ((STRINGS-IS-Empty $___input) -eq 0) { + return "" + } - # execute - $___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}" "*")" "*" - $___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled" - $___output = "${___output}.$((Split-Path -Path ${___input} -Leaf).Split(".")[1])" + # execute + $___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}" "*")" "*" + $___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled" + $___output = "${___output}.$((Split-Path -Path ${___input} -Leaf).Split(".")[1])" - return $___output + return $___output } function UPSCALER-GPU-Scan { - # validate input - $___program = UPSCALER-Program-Get - if ((STRINGS-Is-Empty "${___program}") -eq 0) { - return "" - } - - - # create a dummy PNG file for upscale - $___filename = "${env:UPSCALER_PATH_ROOT}\.dummy.png" - $___target = "${env:UPSCALER_PATH_ROOT}\.dummy-upscaled.png" - $___header = @( - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, - 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - 0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, - 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, - 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x74, 0x52, - 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, - 0x00, 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, - 0x00, 0xAF, 0xC8, 0x37, 0x05, 0x8A, 0xE9, 0x00, - 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, - 0x42, 0x60, 0x82 - ) - $___bytes = [byte[]]$___header - $null = FS-Remove-Silently "${___filename}" - $null = FS-Remove-Silently "${___target}" - [System.IO.File]::WriteAllBytes($___filename, $___bytes) - $___result = & $___program -s 1 -i $___filename -o $___target 2>&1 - $null = FS-Remove-Silently "${___filename}" - $null = FS-Remove-Silently "${___target}" - return $___result + # validate input + $___program = UPSCALER-Program-Get + if ((STRINGS-Is-Empty $___program) -eq 0) { + return "" + } + + + # create a dummy PNG file for upscale + $___filename = "${env:UPSCALER_PATH_ROOT}\.dummy.png" + $___target = "${env:UPSCALER_PATH_ROOT}\.dummy-upscaled.png" + $___header = @( + 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, + 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, + 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, + 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x74, 0x52, + 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, + 0x00, 0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, + 0x00, 0xAF, 0xC8, 0x37, 0x05, 0x8A, 0xE9, 0x00, + 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, + 0x42, 0x60, 0x82 + ) + $___bytes = [byte[]]$___header + $null = FS-Remove-Silently $___filename + $null = FS-Remove-Silently $___target + [System.IO.File]::WriteAllBytes($___filename, $___bytes) + $___result = & $___program -s 1 -i $___filename -o $___target 2>&1 + $null = FS-Remove-Silently $___filename + $null = FS-Remove-Silently $___target + return $___result } function UPSCALER-GPU-Verify { - param( - [string]$___gpu - ) + param( + [string]$___gpu + ) - # validate input - if ((STRINGS-Is-Empty "${___gpu}") -eq 0) { - return 1 - } + # validate input + if ((STRINGS-Is-Empty $___gpu) -eq 0) { + return 1 + } - # execute - $___term = UPSCALER-GPU-Scan - $___verdict = $false - $___lines = $___term -split "`n" - foreach ($___line in $___lines) { - if ($___line -notmatch '^\[') { - continue - } + # execute + $___term = UPSCALER-GPU-Scan + $___verdict = $false + $___lines = $___term -split "`n" + foreach ($___line in $___lines) { + if ($___line -notmatch '^\[') { + continue + } - $___line = $___line -replace '\]\s*$', '' - $___line = $___line -replace '^\[\s*', '' - $___id = $___line.Split(' ', 2)[0] + $___line = $___line -replace '\]\s*$', '' + $___line = $___line -replace '^\[\s*', '' + $___id = $___line.Split(' ', 2)[0] - if ($___gpu -eq $___id) { - $___verdict = $true - break - } - } + if ($___gpu -eq $___id) { + $___verdict = $true + break + } + } - # report status - if ($___verdict) { - return 0 - } + # report status + if ($___verdict) { + return 0 + } - return 1 + return 1 } function UPSCALER-Is-Available { - $___process = UPSCALER-Program-Get - if ((STRINGS-Is-Empty "${___process}") -eq 0) { - return 1 - } + $___process = UPSCALER-Program-Get + if ((STRINGS-Is-Empty $___process) -eq 0) { + return 1 + } - $___process = FS-Is-Target-Exist "${___process}" - if ($___process -ne 0) { - return 1 - } + $___process = FS-Is-Target-Exist $___process + if ($___process -ne 0) { + return 1 + } - # report status - return 0 + # report status + return 0 } function UPSCALER-Model-Get { - param( - [string]$___id - ) + param( + [string]$___id + ) - # validate input - if ((STRINGS-Is-Empty "${___id}") -eq 0) { - return "" - } + # validate input + if ((STRINGS-Is-Empty $___id) -eq 0) { + return "" + } - # execute - foreach ($___model in (Get-ChildItem ` - -Path "${env:UPSCALER_PATH_ROOT}\models" ` - -Filter *.sh)) { - $___model_ID = $___model.Name -replace '\.sh$' - if ($___model_ID -ne $___id) { - continue - } + # execute + foreach ( + $___model in (Get-ChildItem -Path "${env:UPSCALER_PATH_ROOT}\models" -Filter *.sh) + ) { + $___model_ID = $___model.Name -replace '\.sh$' + if ($___model_ID -ne $___id) { + continue + } - # given ID is a valid model - $___model_NAME = "" - $___model_SCALE_MAX = "any" + # given ID is a valid model + $___model_NAME = "" + $___model_SCALE_MAX = "any" - foreach ($___line in $(Get-Content "$($___model.FullName)")) { - $___line = $___line -replace '#.*', '' + foreach ($___line in $(Get-Content "$($___model.FullName)")) { + $___line = $___line -replace '#.*', '' - if ((STRINGS-Is-Empty "${___line}") -eq 0) { - continue - } + if ((STRINGS-Is-Empty $___line) -eq 0) { + continue + } - $___key, $___value = $___line -split '=', 2 - $___key = $___key.Trim() -replace '^''|''$|^"|"$' - $___value = $___value.Trim() -replace '^''|''$|^"|"$' - switch ($___key) { - "model_name" { - $___model_NAME = $___value - } "model_max_scale" { - $___model_SCALE_MAX = $___value - } default { - # unknown - do nothing - }} - } + $___key, $___value = $___line -split '=', 2 + $___key = $___key.Trim() -replace '^''|''$|^"|"$' + $___value = $___value.Trim() -replace '^''|''$|^"|"$' + switch ($___key) { + "model_name" { + $___model_NAME = $___value + } "model_max_scale" { + $___model_SCALE_MAX = $___value + } default { + # unknown - do nothing + }} + } - # print out - return "${___model_ID}│${___model_SCALE_MAX}│${___model_NAME}" - } + # print out + return "${___model_ID}│${___model_SCALE_MAX}│${___model_NAME}" + } - # report status - return "" + # report status + return "" } function UPSCALER-Program-Get { - if (-not (OS-Host-System -eq "windows")) { - return "" - } + if (-not (OS-Host-System -eq "windows")) { + return "" + } - if (-not (OS-Host-Arch -eq "amd64")) { - return "" - } + if (-not (OS-Host-Arch -eq "amd64")) { + return "" + } - return "${env:UPSCALER_PATH_ROOT}/bin/windows-amd64.exe" + return "${env:UPSCALER_PATH_ROOT}/bin/windows-amd64.exe" } function UPSCALER-Run-Image { - param( - [string]$___model, - [string]$___scale, - [string]$___format, - [string]$___gpu, - [string]$___input, - [string]$___output - ) - - - # validate input - if (((STRINGS-Is-Empty "${___model}") -eq 0) -or - ((STRINGS-Is-Empty "${___scale}") -eq 0) -or - ((STRINGS-Is-Empty "${___format}") -eq 0) -or - ((STRINGS-Is-Empty "${___gpu}") -eq 0) -or - ((STRINGS-Is-Empty "${___input}") -eq 0) -or - ((STRINGS-Is-Empty "${___output}") -eq 0)) { - return 1 - } - - - if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { - return 1 - } - - - # construct arugment - $___cmd = "-i '${___input}' -o '${___output}'" - $___cmd = "${___cmd} -m '${env:UPSCALER_PATH_ROOT}/models/' -n '${___model}'" - $___cmd = "${___cmd} -s '${___scale}' -g '${___gpu}'" - switch ($___format) { - "jpg" { - $___cmd = "${___cmd} -f jpg" - } "webp" { - $___cmd = "${___cmd} -f webp" - } default { - # do nothing - maintain png - }} - - - # execute - $null = FS-Make-Housing-Directory "${___output}" - $null = FS-Remove-Silently "${___output}" - if ((STRINGS-Is-Empty "${env:UPSCALER_TEST_MODE}") -ne 0) { - $null = I18N-Report-Simulation "$(UPSCALER-Program-Get) ${___cmd}" - $___process = FS-Copy-File "${___input}" "${___output}" - if ($___process -eq 0) { - return 0 - } - } else { - $___process = OS-Exec "$(UPSCALER-Program-Get)" "${___cmd}" - if ($___process -eq 0) { - return 0 - } - } - - - # report status - return 1 + param( + [string]$___model, + [string]$___scale, + [string]$___format, + [string]$___gpu, + [string]$___input, + [string]$___output + ) + + + # validate input + if ( + ((STRINGS-Is-Empty $___model) -eq 0) -or + ((STRINGS-Is-Empty $___scale) -eq 0) -or + ((STRINGS-Is-Empty $___format) -eq 0) -or + ((STRINGS-Is-Empty $___gpu) -eq 0) -or + ((STRINGS-Is-Empty $___input) -eq 0) -or + ((STRINGS-Is-Empty $___output) -eq 0) + ) { + return 1 + } + + if ((STRINGS-Is-Empty "$(UPSCALER-Program-Get)") -eq 0) { + return 1 + } + + + # construct arugment + $___cmd = "-i '${___input}' -o '${___output}'" + $___cmd = "${___cmd} -m '${env:UPSCALER_PATH_ROOT}/models/' -n '${___model}'" + $___cmd = "${___cmd} -s '${___scale}' -g '${___gpu}'" + switch ($___format) { + "jpg" { + $___cmd = "${___cmd} -f jpg" + } "webp" { + $___cmd = "${___cmd} -f webp" + } default { + # do nothing - maintain png + }} + + + # execute + $null = FS-Make-Housing-Directory $___output + $null = FS-Remove-Silently $___output + if ((STRINGS-Is-Empty ${env:UPSCALER_TEST_MODE}) -ne 0) { + $null = I18N-Report-Simulation "$(UPSCALER-Program-Get) ${___cmd}" + $___process = FS-Copy-File $___input $___output + if ($___process -eq 0) { + return 0 + } + } else { + $___process = OS-Exec "$(UPSCALER-Program-Get)" $___cmd + if ($___process -eq 0) { + return 0 + } + } + + + # report status + return 1 } function UPSCALER-Scale-Get { - param( - [string]$___limit, - [string]$___input - ) - - - # validate input - if ( - ((STRINGS-Is-Empty "${___limit}") -eq 0) -or - ((STRINGS-Is-Empty "${___input}") -eq 0)) { - return 0 - } - - - # execute - switch ($___limit) { - "any" { - switch ($___input) { - "1" { - return 1 - } "2" { - return 2 - } "3" { - return 3 - } "4" { - return 4 - } default { - }} - } "1" { - switch ($___input) { - "1" { - return 1 - } default { - }} - } "2" { - switch ($___input) { - "2" { - return 2 - } default { - }} - } "3" { - switch ($___input) { - "3" { - return 3 - } default { - }} - } "4" { - switch ($___input) { - "4" { - return 4 - } default { - }} - } default { - }} - - - # report status - return 0 + param( + [string]$___limit, + [string]$___input + ) + + + # validate input + if ( + ((STRINGS-Is-Empty $___limit) -eq 0) -or + ((STRINGS-Is-Empty $___input) -eq 0) + ) { + return 0 + } + + + # execute + switch ($___limit) { + "any" { + switch ($___input) { + "1" { + return 1 + } "2" { + return 2 + } "3" { + return 3 + } "4" { + return 4 + } default { + }} + } "1" { + switch ($___input) { + "1" { + return 1 + } default { + }} + } "2" { + switch ($___input) { + "2" { + return 2 + } default { + }} + } "3" { + switch ($___input) { + "3" { + return 3 + } default { + }} + } "4" { + switch ($___input) { + "4" { + return 4 + } default { + }} + } default { + }} + + + # report status + return 0 } diff --git a/tests/01_test_upscale_image_single.sh.ps1 b/tests/01_test_upscale_image_single.sh.ps1 index a8963cb..245e2a3 100755 --- a/tests/01_test_upscale_image_single.sh.ps1 +++ b/tests/01_test_upscale_image_single.sh.ps1 @@ -26,8 +26,8 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null ################################################################################ $PSDefaultParameterValues['*:Encoding'] = 'utf8' $OutputEncoding = [console]::InputEncoding ` - = [console]::OutputEncoding ` - = New-Object System.Text.UTF8Encoding + = [console]::OutputEncoding ` + = New-Object System.Text.UTF8Encoding # Scan for fundamental pathing @@ -35,32 +35,32 @@ ${env:UPSCALER_PATH_PWD} = Get-Location ${env:UPSCALER_PATH_SCRIPTS} = "init" if (Test-Path ".\start.ps1") { - # currently inside the automataCI directory. - ${env:UPSCALER_PATH_ROOT} = Split-Path -Parent "${env:UPSCALER_PATH_PWD}" + # currently inside the automataCI directory. + ${env:UPSCALER_PATH_ROOT} = Split-Path -Parent "${env:UPSCALER_PATH_PWD}" } elseif (Test-Path ".\${env:UPSCALER_PATH_SCRIPTS}\start.ps1") { - # current directory is the root directory. - ${env:UPSCALER_PATH_ROOT} = "${env:UPSCALER_PATH_PWD}" + # current directory is the root directory. + ${env:UPSCALER_PATH_ROOT} = "${env:UPSCALER_PATH_PWD}" } else { - # scan from current directory - bottom to top - $__pathing = "${env:UPSCALER_PATH_PWD}" - ${env:UPSCALER_PATH_ROOT} = "" - foreach ($__pathing in (${env:UPSCALER_PATH_PWD}.Split("\"))) { - if (-not [string]::IsNullOrEmpty($env:UPSCLAER_PATH_ROOT)) { - ${env:UPSCALER_PATH_ROOT} += "\" - } - ${env:UPSCALER_PATH_ROOT} += "${__pathing}" - - if (Test-Path -Path ` - "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}\start.ps1") { - break - } - } - $null = Remove-Variable -Name __pathing - - if (-not (Test-Path "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}\start.ps1")) { - Write-Error "[ ERROR ] Missing root directory.`n`n" - exit 1 - } + # scan from current directory - bottom to top + $__pathing = "${env:UPSCALER_PATH_PWD}" + ${env:UPSCALER_PATH_ROOT} = "" + foreach ($__pathing in (${env:UPSCALER_PATH_PWD}.Split("\"))) { + if ($env:UPSCLAER_PATH_ROOT -ne "") { + ${env:UPSCALER_PATH_ROOT} += "\" + } + ${env:UPSCALER_PATH_ROOT} += "${__pathing}" + + if (Test-Path -Path ` + "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}\start.ps1") { + break + } + } + $null = Remove-Variable -Name __pathing + + if (-not (Test-Path "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}\start.ps1")) { + Write-Error "[ ERROR ] Missing root directory.`n`n" + exit 1 + } } ${env:LIBS_UPSCALER} = "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}" @@ -70,6 +70,7 @@ ${env:LIBS_UPSCALER} = "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}" # import fundamental libraries . "${env:LIBS_UPSCALER}\services\i18n\__printer.ps1" +. "${env:LIBS_UPSCALER}\services\io\os.ps1" @@ -78,36 +79,39 @@ ${env:LIBS_UPSCALER} = "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}" $null = I18N-Status-Print "note" "RUNNING HELP TEST SUITE`n`n`n" $__verdict = $true +if (-not (OS-Host-Arch -eq "amd64")) { + I18N-Status-Print "error" "TEST SUITE SKIPPED: unsupported test machine.`n`n`n" + exit 0 +} + $null = I18N-Status-Print "note" "test single image upscale...`n" $__process = . "${env:LIBS_UPSCALER}\start.ps1" ` - "--model" "upscayl-nmkd-4x-superscale-sd-178000-g" ` - "--scale" "4" ` - "--parallel" "2" ` - "--input" "${env:UPSCALER_PATH_ROOT}\tests\image\sample-01.jpeg" ` - "--output" "${env:UPSCALER_PATH_ROOT}\tmp\test-01\sample-01-upscaled.png" + "--model" "upscayl-nmkd-4x-superscale-sd-178000-g" ` + "--scale" "4" ` + "--parallel" "2" ` + "--input" "${env:UPSCALER_PATH_ROOT}\tests\image\sample-01.jpeg" ` + "--output" "${env:UPSCALER_PATH_ROOT}\tmp\test-01\sample-01-upscaled.png" if ($__process -ne 0) { - $null = I18N-Status-Print "error" "Failed - bad processing.`n`n" - $__verdict = $false + $null = I18N-Status-Print "error" "Failed - bad processing.`n`n" + $__verdict = $false } if (-not (Test-Path -Path "${env:UPSCALER_PATH_ROOT}\tmp\test-01\sample-01-upscaled.png")) { - $null = I18N-Status-Print "error" "Failed - missing output.`n`n" - $__verdict = $false + $null = I18N-Status-Print "error" "Failed - missing output.`n`n" + $__verdict = $false } # report verdict if (-not $__verdict) { - $null = I18N-Status-Print "error" "TEST SUITE FAILED.`n`n`n" - exit 1 + $null = I18N-Status-Print "error" "TEST SUITE FAILED.`n`n`n" + exit 1 } $null = I18N-Status-Print "success" "TEST SUITE PASSED.`n`n`n" exit 0 - - ################################################################################ # Windows POWERSHELL Codes # ################################################################################ @@ -163,6 +167,7 @@ export LIBS_UPSCALER="${UPSCALER_PATH_ROOT}/${UPSCALER_PATH_SCRIPTS}" # import fundamental libraries . "${LIBS_UPSCALER}/services/i18n/__printer.sh" +. "${LIBS_UPSCALER}/services/io/os.sh" @@ -172,29 +177,39 @@ I18N_Status_Print "note" "RUNNING HELP TEST SUITE\n\n\n" __verdict=0 +# check test machine compatibility +case "$(OS_Host_Arch)" in +amd64) + ;; +*) + I18N_Status_Print "warning" "TEST SUITE SKIPPED: unsupported test machine.\n\n\n" + exit 0 + ;; +esac + + I18N_Status_Print "note" "test single image upscale...\n" . "${LIBS_UPSCALER}"/start.sh \ - --model upscayl-nmkd-4x-superscale-sd-178000-g \ - --scale 4 \ - --parallel 2 \ - --input "${UPSCALER_PATH_ROOT}/tests/image/sample-01.jpeg" \ - "--output" "${UPSCALER_PATH_ROOT}/tmp/test-01/sample-01-upscaled.png" + --model upscayl-nmkd-4x-superscale-sd-178000-g \ + --scale 4 \ + --parallel 2 \ + --input "${UPSCALER_PATH_ROOT}/tests/image/sample-01.jpeg" \ + "--output" "${UPSCALER_PATH_ROOT}/tmp/test-01/sample-01-upscaled.png" if [ $? -ne 0 ]; then - I18N_Status_Print "error" "Failed - bad processing.\n\n" - __verdict=1 + I18N_Status_Print "error" "Failed - bad processing.\n\n" + __verdict=1 fi if [ ! -f "${UPSCALER_PATH_ROOT}/tmp/test-01/sample-01-upscaled.png" ]; then - I18N_Status_Print "error" "Failed - missing output.\n\n" - __verdict=1 + I18N_Status_Print "error" "Failed - missing output.\n\n" + __verdict=1 fi - # report verdict if [ "$__verdict" != "0" ]; then - I18N_Status_Print "error" "TEST SUITE FAILED.\n\n\n" - exit 1 + I18N_Status_Print "error" "TEST SUITE FAILED.\n\n\n" + exit 1 fi I18N_Status_Print "success" "TEST SUITE PASSED.\n\n\n"