pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: movead.li@highgo.ca <movead.li@highgo.ca>
To: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Email to hackers for test coverage
Date: Thu, 22 Aug 2019 17:46:38 +0800
Message-ID: <20190822174636998766188@highgo.ca> (raw)

Hello hackers,

One of the area that didn't get much attention in the community
recently is analysing and increasing the code coverage of 
PostgreSQL regession test suite. I have started working on the
code coverage by running the GCOV code coverage analysis tool in
order to analyse the current code coverage and come up with test
cases to increase the code coverage. This is going to be a long
exercise so my plan is do it incrementaly. I will be analysing
some area of untested code and then coming up with test cases to
test those lines of code in regression and then moving on next
area of untested code and so on.

So far I have come up with 3 test cases to increase the code
coverage of PostgreSQL regression test suite.

I have performed the regression run for this exercise on this commit:
(Commit version 75c1921cd6c868c5995b88113b4463a4830b9a27):

The regression is executed with make check-world command and the
results are gathered using  'make coverage-html' command. 

Below are the lines of untested code that i have analysed and the
test cases added to regression to test these as part of regression.

1. src/include/utils/float.h:140

Analyze: 
This is an error report line when converting a big float8 value
which a float4 can not storage to float4.

Test case:
Add a test case as below in file float4.sql:
select float4(1234567890123456789012345678901234567890::float8);

2. src/include/utils/float.h:145

Analyze:
This is an error report line when converting a small float8 value
which a float4 can not storage to float4.

Test case:
Add a test case as below in file float4.sql:
select float4(0.0000000000000000000000000000000000000000000001::float8);

3.src/include/utils/sortsupport.h:264

Analyze:
It is reverse sorting for the data type that has abbreviated for
sort, for example macaddr, uuid, numeric, network and I choose
numeric to do it.

Test cast:
Add a test case as below in file numeric.sql:
INSERT INTO num_input_test(n1) values('99999999999999999999999999.998');
INSERT INTO num_input_test(n1) values('99999999999999999999999999.997');
SELECT * FROM num_input_test ORDER BY n1 DESC;

Result and patch

By adding the test cases, the test coverage of  float.h increased from
97.7% to 100% and sortsupport.h increased from 76.7% to 80.0%.
 
The increase in code coverage can be seen in the before and after
pictures of GCOV test coverage analysis summary.

The attached patch contain the test cases added in regression for
increasing the coverage.


--
Movead Li


Attachments:

  before.png (application/octet-stream, 41.3K) download

  after.png (application/octet-stream, 15.6K) download

regression_20190820.patch (application/octet-stream, 3.6K) download diff --git a/src/test/regress/expected/float4.out b/src/test/regress/expected/float4.out index 901abb1d27..0f0dbe0689 100644 --- a/src/test/regress/expected/float4.out +++ b/src/test/regress/expected/float4.out @@ -939,3 +939,8 @@ drop cascades to cast from xfloat4 to real drop cascades to cast from real to xfloat4 drop cascades to cast from xfloat4 to integer drop cascades to cast from integer to xfloat4 +-- Add test case for float4() type fonversion function +select float4(1234567890123456789012345678901234567890::float8); +ERROR: value out of range: overflow +select float4(0.0000000000000000000000000000000000000000000001::float8); +ERROR: value out of range: underflow diff --git a/src/test/regress/expected/numeric.out b/src/test/regress/expected/numeric.out index 1cb3c3bfab..289c930265 100644 --- a/src/test/regress/expected/numeric.out +++ b/src/test/regress/expected/numeric.out @@ -1426,6 +1426,8 @@ INSERT INTO num_input_test(n1) VALUES ('555.50'); INSERT INTO num_input_test(n1) VALUES ('-555.50'); INSERT INTO num_input_test(n1) VALUES ('NaN '); INSERT INTO num_input_test(n1) VALUES (' nan'); +INSERT INTO num_input_test(n1) values('99999999999999999999999999.998'); +INSERT INTO num_input_test(n1) values('99999999999999999999999999.997'); -- bad inputs INSERT INTO num_input_test(n1) VALUES (' '); ERROR: invalid input syntax for type numeric: " " @@ -1459,17 +1461,19 @@ INSERT INTO num_input_test(n1) VALUES (' N aN '); ERROR: invalid input syntax for type numeric: " N aN " LINE 1: INSERT INTO num_input_test(n1) VALUES (' N aN '); ^ -SELECT * FROM num_input_test; - n1 ---------- - 123 - 3245874 - -93853 - 555.50 - -555.50 - NaN - NaN -(7 rows) +SELECT * FROM num_input_test ORDER BY n1 DESC; + n1 +-------------------------------- + NaN + NaN + 99999999999999999999999999.998 + 99999999999999999999999999.997 + 3245874 + 555.50 + 123 + -555.50 + -93853 +(9 rows) -- -- Test some corner cases for multiplication diff --git a/src/test/regress/sql/float4.sql b/src/test/regress/sql/float4.sql index afdb469dc8..fecc0a7d17 100644 --- a/src/test/regress/sql/float4.sql +++ b/src/test/regress/sql/float4.sql @@ -345,3 +345,7 @@ select float4send(flt) as ibits, -- clean up, lest opr_sanity complain drop type xfloat4 cascade; + +-- Add test case for float4() type fonversion function +select float4(1234567890123456789012345678901234567890::float8); +select float4(0.0000000000000000000000000000000000000000000001::float8); \ No newline at end of file diff --git a/src/test/regress/sql/numeric.sql b/src/test/regress/sql/numeric.sql index a939412359..51895c426b 100644 --- a/src/test/regress/sql/numeric.sql +++ b/src/test/regress/sql/numeric.sql @@ -839,6 +839,8 @@ INSERT INTO num_input_test(n1) VALUES ('555.50'); INSERT INTO num_input_test(n1) VALUES ('-555.50'); INSERT INTO num_input_test(n1) VALUES ('NaN '); INSERT INTO num_input_test(n1) VALUES (' nan'); +INSERT INTO num_input_test(n1) values('99999999999999999999999999.998'); +INSERT INTO num_input_test(n1) values('99999999999999999999999999.997'); -- bad inputs INSERT INTO num_input_test(n1) VALUES (' '); @@ -850,7 +852,7 @@ INSERT INTO num_input_test(n1) VALUES ('5. 0 '); INSERT INTO num_input_test(n1) VALUES (''); INSERT INTO num_input_test(n1) VALUES (' N aN '); -SELECT * FROM num_input_test; +SELECT * FROM num_input_test ORDER BY n1 DESC; -- -- Test some corner cases for multiplication

view thread (15+ messages)  latest in thread

Message-ID: <20190822174636998766188@highgo.ca>
Permalink:  ../20190822174636998766188@highgo.ca/
Also on:    postgresql.org/message-id/20190822174636998766188@highgo.ca

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: movead.li@highgo.ca
  Subject: Re: Email to hackers for test coverage
  In-Reply-To: <20190822174636998766188@highgo.ca>
  References: <20190822174636998766188@highgo.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox