Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for NORM2 #839

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/f90_correct/inc/norm2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

EXE=norm2.$(EXESUFFIX)

build: $(SRC)/norm2.F90
-$(RM) norm2.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
-$(RM) $(OBJ)
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX)
@echo ------------------------------------ building test $@
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2.F90 check.$(OBJX) -o norm2.$(EXESUFFIX)
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2.F90 check.$(OBJX) -r8 -o norm2R8.$(EXESUFFIX)

run:
@echo ------------------------------------ executing test norm2
norm2.$(EXESUFFIX)
norm2R8.$(EXESUFFIX)

verify: ;

norm2.run: run
32 changes: 32 additions & 0 deletions test/f90_correct/inc/norm2_double_precision.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

EXE=norm2_double_precision.$(EXESUFFIX)

build: $(SRC)/norm2_double_precision.F90
-$(RM) norm2_double_precision.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
-$(RM) $(OBJ)
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX)
@echo ------------------------------------ building test $@
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2_double_precision.F90 check.$(OBJX) -o norm2_double_precision.$(EXESUFFIX)

run:
@echo ------------------------------------ executing test Norm2 Double Precicion
norm2_double_precision.$(EXESUFFIX)

verify: ;

norm2_double_precision.run: run
29 changes: 29 additions & 0 deletions test/f90_correct/inc/norm2_error.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

build: clean
@echo ------------------------------------ building test $(TEST)
# -@$(CP) $(SRC)/$(TEST).f90 .
-$(FC) -c $(FCFLAGS) $(SRC)/$(TEST).f90 > $(TEST).rslt 2>&1

run:
@echo ------------------------------------ test $(TEST) not expected to execute

verify:
@echo ------------------------------------ verifying test $(TEST)
$(COMP_CHECK) $(SRC)/$(TEST).f90 $(TEST).rslt $(FC)

clean:
-@$(RM) $(TEST).rslt $(TEST).$(OBJX) *.mod $(TEST).$(EXE)

34 changes: 34 additions & 0 deletions test/f90_correct/inc/norm2_function.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

EXE=norm2_function.$(EXESUFFIX)

build: $(SRC)/norm2_function.F90
-$(RM) norm2_function.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
-$(RM) $(OBJ)
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX)
@echo ------------------------------------ building test $@
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2_function.F90 check.$(OBJX) -o norm2_function.$(EXESUFFIX)
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2.F90 check.$(OBJX) -r8 -o norm2R8_function.$(EXESUFFIX)

run:
@echo ------------------------------------ executing test norm2_function
norm2_function.$(EXESUFFIX)
norm2R8_function.$(EXESUFFIX)

verify: ;

norm2_function.run: run
32 changes: 32 additions & 0 deletions test/f90_correct/inc/norm2_single_precision.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

EXE=norm2_single_precision.$(EXESUFFIX)

build: $(SRC)/norm2_single_precision.F90
-$(RM) norm2_single_precision.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
-$(RM) $(OBJ)
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX)
@echo ------------------------------------ building test $@
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/norm2_single_precision.F90 check.$(OBJX) -o norm2_single_precision.$(EXESUFFIX)

run:
@echo ------------------------------------ executing test Norm2 Single Precicion
norm2_single_precision.$(EXESUFFIX)

verify: ;

norm2_single_precision.run: run
19 changes: 19 additions & 0 deletions test/f90_correct/lit/norm2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
21 changes: 21 additions & 0 deletions test/f90_correct/lit/norm2_double_precision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared lit script for each tests. Run bash commands that run tests with make.
# Due to: https://github.com/flang-compiler/flang/issues/837

# XFAIL: *
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
19 changes: 19 additions & 0 deletions test/f90_correct/lit/norm2_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
19 changes: 19 additions & 0 deletions test/f90_correct/lit/norm2_function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
19 changes: 19 additions & 0 deletions test/f90_correct/lit/norm2_single_precision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2019, Arm Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
87 changes: 87 additions & 0 deletions test/f90_correct/src/norm2.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
! Copyright (c) 2019, Arm Ltd. All rights reserved.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.

program test

implicit none

real, parameter :: tolerance = 1.E-12
integer, parameter :: expec (2) = [1, 1]
integer :: res(2)
integer :: sz, i
real :: x1(5) = [real::1, 2, 3, 4, 5]
real :: x2(6) = [real:: 1, 2, 3, 4, 5, 999999999]
real, allocatable :: x3(:)
real, dimension (-2:2) :: x4
real :: matrix2(3,3) = reshape((/1,2,3,1,2,3,1,2,3/), (/3,3/))
real :: resultsA(10)
real :: resultsB(10)
real :: resultsC

! Tests array constructor as argument
resultsA(1) = norm2(x1)
resultsB(1) = norm2(x2(1:5))
resultsC = norm2([real:: 1, 2, 3, 4, 5])

! Tests allocatable array as argument
sz = 3
allocate (x3(sz))
do i=1, sz
x3(i) = i*i
enddo
resultsA(2) = norm2(x3)
resultsB(2) = sqrt(dot_product(x3, x3))

! Test dim
resultsA(3:5) = norm2(matrix2, 1)
resultsB(3) = sqrt(dot_product(matrix2(:,1), matrix2(:,1)))
resultsB(4) = sqrt(dot_product(matrix2(:,2), matrix2(:,2)))
resultsB(5) = sqrt(dot_product(matrix2(:,3), matrix2(:,3)))
resultsA(6:8) = norm2(matrix2, 2)
resultsB(6) = sqrt(dot_product(matrix2(1,:), matrix2(1,:)))
resultsB(7) = sqrt(dot_product(matrix2(2,:), matrix2(2,:)))
resultsB(8) = sqrt(dot_product(matrix2(3,:), matrix2(3,:)))

x4 = [real :: -1, -2, 0, 10, 100]
! Test Adjustable Arrays
resultsA(9) = norm2(x4,1)
resultsB(9) = sqrt(dot_product(x4, x4))

! Test assumed shape
resultsA(10) = norm2(x4(1:2))
resultsB(10) = sqrt(dot_product(x4(1:2), x4(1:2)))

if (abs(resultsA(1) - resultsB(1)) < tolerance) then
if (abs(resultsB(1) - resultsC) < tolerance) then
res(1) = 1
print *, 'arrays tests match'
else
res(1) = -1
print *, 'arrays tests mismatch'
endif
else
res(1) = -2
print *, 'arrays tests mismatch'
endif

if(all(abs(resultsA(2:10)-resultsB(2:10)) < tolerance)) then
res(2) = 1
print *, 'expect vs results match'
else
res(2) = -1
print *, 'expect vs results mismatch'
end if

call check(res, expec, 2)
end program