Skip to content

Commit

Permalink
Merge branch 'dev' (early part)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 1, 2019
2 parents b06eadc + 4aa44de commit 967f01e
Show file tree
Hide file tree
Showing 32 changed files with 460 additions and 187 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ javascript/node_modules/**
.vscode/**
**log*.txt
**/a.out
**/*.x86*
**/*.exe
**/*.aarch64
**/objs/**
**/build/**
venv/**
21 changes: 2 additions & 19 deletions .scripts/appveyor_script.bat
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
IF DEFINED PIP (
ECHO %PYTHON% %PYTHON_VERSION%%APPVEYOR_BUILD_FOLDER%
ECHO "3"
set HOME=%APPVEYOR_BUILD_FOLDER%
ECHO "4"
%PYPY%
dir -r
dir /S
ECHO "5"
cd python
ECHO "6"
%PIP% install -r requirements.txt
IF DEFINED LINT (
ECHO "7"
%RUN% -m pytest -v --mypy --mypy-ignore-missing-imports --flake8 --isort -k "not test_problem and not test_is_prime" || goto :error
%RUN% -m pytest -v --mypy --mypy-ignore-missing-imports --flake8 --isort -k "not test_problem and not test_is_prime and not test_groupwise" || goto :error
) ELSE (
ECHO "7"
%RUN% -m pytest test_euler.py -v --benchmark-min-time=0.05 --benchmark-sort=fullname --benchmark-verbose || goto :error
)
) ELSE (
IF DEFINED NODE (
dir C:\avvm\node
ECHO "3"
powershell -Command "Install-Product node $env:NODE"
ECHO "4"
cd javascript
ECHO "5"
IF DEFINED LINT (
npm install eslint-config-google@latest eslint@>=5.16.0
ECHO "6"
npx eslint *.js || goto :error
) ELSE (
npm install
ECHO "6"
npx mocha || goto :error
)
) ELSE (
cd c
C:\Python36\python -m pip install -r requirements.txt
%WIN_SDK%
ECHO %VCVARS%
%VCVARS%
C:\Python36\python -m pytest test_euler.py -v --benchmark-min-time=0.05 --benchmark-sort=fullname --benchmark-verbose || goto :error
C:\Python36\python -m pytest test_euler.py -v --benchmark-min-time=0.05 --benchmark-group-by=fullfunc --benchmark-sort=fullname --benchmark-verbose || goto :error
)
)
goto :EOF
Expand Down
21 changes: 19 additions & 2 deletions .scripts/shippable_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@ else
if [ $linter ]; then
sudo apt-get update
sudo apt-get install -y clang-tidy
make clint
cd c
clang-tidy --help
clang-tidy *.c
else
sudo apt-get update
sudo apt-get install -y gcc clang tcc python3-pip
if [ $pcc ]; then
sudo apt-get install -y build-essential flex bison
mkdir pcc pcc-libs
wget -O - -o /dev/null http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/pcc-1.1.0.tgz | tar -xz --no-seek -C pcc --strip-components=1
wget -O - -o /dev/null http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/pcc-libs-1.1.0.tgz | tar -xz --no-seek -C pcc-libs --strip-components=1
cd pcc
sed -i 's/MANPAGE=@BINPREFIX@cpp/MANPAGE=@BINPREFIX@pcc-cpp/' cc/cpp/Makefile.in
./configure --prefix=/usr --libexecdir=/usr/lib/{x86_64,i386}-linux-gnu
sudo make && sudo make install
cd ../pcc-libs
./configure --prefix=/usr --libexecdir=/usr/lib/{x86_64,i386}-linux-gnu
sudo make && sudo make install
cd ..
else
sudo apt-get install -y $COMPILER_OVERRIDE python3-pip
fi
cd c && make test USER_FLAG=
fi
fi
25 changes: 24 additions & 1 deletion .scripts/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,35 @@ if [ $pyver ]; then
else
make pytest PY=python LINT=false MYPY= USER_FLAG=
fi
else
elif [ $jsver ]; then
if [ $linter ]; then
cd javascript;
npm install eslint-config-google@latest eslint@>=5.16.0;
npx eslint *.js && echo "Linting successful!"
else
make jstest;
fi
else
if [ $linter ]; then
brew install llvm;
ln -s "/usr/local/opt/llvm/bin/clang-tidy" "/usr/local/bin/clang-tidy";
make clint;
else
if [ $pcc ]; then
brew install flex bison
mkdir pcc pcc-libs
wget -O - -o /dev/null http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/pcc-1.1.0.tgz | tar -xz -C pcc --strip-components=1
wget -O - -o /dev/null http://pcc.ludd.ltu.se/ftp/pub/pcc-releases/pcc-libs-1.1.0.tgz | tar -xz -C pcc-libs --strip-components=1
cd pcc
./configure
sudo make && sudo make install
cd ../pcc-libs
./configure
sudo make && sudo make install
cd ..
elif [ $GCC_OVERRIDE ]; then
brew install gcc;
fi
make ctest;
fi
fi
4 changes: 1 addition & 3 deletions .stignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
**/.mypy_cache/**
javascript/node_modules/**
**/a.out
**/*.x86*
**/*.exe
**/*.aarch64
**/objs/**
**/build/**
venv/**
17 changes: 12 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ matrix:
# pydist=macports
# pydist=homebrew
- language: node_js
node_js: "10"
node_js: "11"
os: osx
env: jsver=10 linter=true
env: jsver=11 linter=true
- language: c
os: osx
env: linter=true
script: brew install llvm; ln -s "/usr/local/opt/llvm/bin/clang-tidy" "/usr/local/bin/clang-tidy"; make clint
- language: node_js
node_js: "11"
os: osx
env: jsver=11
- language: node_js
node_js: "10"
os: osx
Expand All @@ -29,12 +32,13 @@ matrix:
- language: c
os: osx
env: COMPILER_OVERRIDE=clang
script: brew install clang python3; make ctest
- language: c
os: osx
env: COMPILER_OVERRIDE=gcc GCC_OVERRIDE=gcc-9
osx_image: xcode10.1
script: brew install gcc; make ctest
- language: c
os: osx
env: COMPILER_OVERRIDE=pcc pcc=true
- language: generic
python: 3.6
os: osx
Expand All @@ -57,6 +61,9 @@ matrix:
python: pypy3
os: osx
env: pyver=pypy3 pydist=homebrew NO_SLOW=true
allow_failures:
- env: COMPILER_OVERRIDE=pcc pcc=true
- python: pypy3

script:
- sh ./.scripts/travis_script.sh
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ The repo is divided into sections for each language. The top-level Makefile will

## Footnotes

1: Windows testing is only enabled for Python and Javascript at the moment until I get configuration set up correctly for CL
1: Windows testing is done on C, Python, and Javascript. C compilers are CL (MSVC 2015/2017 x86/x64) and clang

2: Linux testing is done on Ubuntu 14.04 for C, Python, and Javascript. C compilers are gcc, clang, and tcc
2: Linux testing is done on Ubuntu 14.04 for C, Python, and Javascript. C compilers are gcc, clang, tcc, and pcc. The pcc and tcc compilers are marked as allowed failures because tcc implements no optimizations and might have time failures, and pcc seems to have errors including `<math.h>` and `<stdlib.h>`

3: OSX testing is done on C, Python, and Javascript. C compilers are gcc and clang
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
image:
- Visual Studio 2017

environment:
matrix:
- NODE: "11"
Expand All @@ -9,6 +12,31 @@ environment:
PIP: "%PYTHON%\\Scripts\\pip"
LINT: "true"

- C: "VS 2015 x86"
VCVARS: 'call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86'
COMPILER_OVERRIDE: 'cl'
NO_SLOW: "true"

- C: "VS 2015 x86_64"
WIN_SDK: 'call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64'
VCVARS: 'call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64'
COMPILER_OVERRIDE: 'cl'
NO_SLOW: "true"

- C: "VS 2017 x86"
VCVARS: 'call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"'
COMPILER_OVERRIDE: 'cl'
NO_SLOW: "true"

- C: "VS 2017 x86_64"
VCVARS: 'call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"'
COMPILER_OVERRIDE: 'cl'
NO_SLOW: "true"

- C: "Clang"
COMPILER_OVERRIDE: 'clang'
NO_SLOW: "true"

- NODE: "8"
- NODE: "9"
- NODE: "10"
Expand Down Expand Up @@ -44,9 +72,16 @@ environment:
PYPY: "powershell.exe %APPVEYOR_BUILD_FOLDER%\\.scripts\\installpypy3.ps1"
NO_SLOW: "true"

- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7"
RUN: "%PYTHON%\\python"
PIP: "%PYTHON%\\Scripts\\pip"
ONLY_SLOW: "true"

matrix:
allow_failures:
- PYTHON_VERSION: "pypy3"
- ONLY_SLOW: "true"

test: off

Expand Down
16 changes: 11 additions & 5 deletions c/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

PY?=python3
PROXY?=
USER_FLAG?=--user
PIP?=$(PY) -m pip

ifneq ($(PROXY), )
PROXY_ARG="--proxy=$(PROXY)"
ifneq ($(https_proxy), )
PROXY_ARG=--proxy=$(https_proxy)
else
ifneq ($(http_proxy), )
PROXY_ARG=--proxy=$(http_proxy)
else
PROXY_ARG=
endif
endif

test_%: dependencies
$(PY) -m pytest -v -n$* test_euler.py
Expand All @@ -20,4 +22,8 @@ dependencies:
$(PIP) install -r requirements.txt $(USER_FLAG) $(PROXY_ARG)

lint:
clang-tidy *.c # -warnings-as-errors=*
if test -z "$(clang-tidy p0000_template.c -warnings-as-errors=* 2>&1 | grep "Unknown command line argument")"; then \
clang-tidy *.c -warnings-as-errors=*; \
else \
clang-tidy *.c; \
fi
17 changes: 16 additions & 1 deletion c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ This recipe runs tests in multiple threads, using however many are specified by

## Tests

### Compiler Detection Macros

There are a set of macros which detect which compiler is being used. These macros are mostly used to route around issues with particular compilers. For instance, PCC does not allow me to include `<stdlib.h>` or `<math.h>` on the systems I've tested it on, so I need to route around that. This test checks that those macros are correct.

### Prime Infrastructure Test

This test checks five things:

1. It checks `is_prime()` for numbers up to `MAX_PRIME`, where that is defined in the test
2. It checks that `is_composite()` returns truthy values on composites in that range, and falsey values on primes
3. It checks that `is_composite()` returns the smallest prime factor on composite numbers
4. It checks that the prime numbers are generated in the correct order
5. It checks that all these operations are completed in less than 200ns * `MAX_PRIME`

### Generic Problems

For each problem it will check the answer against a known dictionary. If the problem is not in the "known slow" category (meaning that I generate the correct answer with a poor solution), it will run it as many times as the benchmark plugin wants. Otherwise it is run exactly once.
Expand All @@ -42,11 +56,12 @@ Note that there are optional test that leverage the Python infrastructure. If yo

If this variable is defined, it should contain a comma-separated list of the compilers you would like to test from the following list (case insensitive):

* aocc (not yet supported)
* cl
* clang
* gcc
* icc (not yet supported)
* pcc (not yet supported)
* pcc (partial support)
* tcc

If this variable is not defined, compilers will be auto-detected using `which()`.
Expand Down
14 changes: 12 additions & 2 deletions c/include/digits.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#ifndef _DIGITS
#define _DIGITS

#include "macros.h"
#include "iterator.h"
#include <stdlib.h>
#include <math.h>

#if !PCC_COMPILER
#include <stdlib.h>
#include <math.h>
#else
#include "math.h"
#endif

typedef struct digit_counter digit_counter;
struct digit_counter {
Expand All @@ -22,7 +28,11 @@ unsigned char advance_digit_counter(digit_counter *dc) {
digit_counter digits(unsigned long long n) {
digit_counter ret;
IteratorInitHead(ret, advance_digit_counter);
#if !PCC_COMPILER
size_t digit_len = ceil(log10(n + 1));
#else
size_t digit_len = imprecise_log10(n + 1);
#endif
ret.digits = (unsigned char *) malloc(digit_len * sizeof(unsigned char));
for (size_t i = 0; i < digit_len; i++) {
ret.digits[i] = n % 10;
Expand Down
15 changes: 12 additions & 3 deletions c/include/macros.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _MACROS_H
#define _MACROS_H

#ifdef _MSC_VER
#if (defined(_MSC_VER) && !defined(__clang__))
#define CL_COMPILER 1
#else
#define CL_COMPILER 0
Expand All @@ -11,7 +11,7 @@
#else
#define CLANG_COMPILER 0
#endif
#if (defined(__GNUC__) && !defined(__clang__)) && !defined(__INTEL_COMPILER)
#if (defined(__GNUC__) && !defined(__clang__)) && !defined(__INTEL_COMPILER) && !defined(__PCC__)
#define GCC_COMPILER 1
#else
#define GCC_COMPILER 0
Expand All @@ -21,7 +21,12 @@
#else
#define INTEL_COMPILER 0
#endif
#define PCC_COMPILER 0
#define AMD_COMPILER 0
#ifdef __PCC__
#define PCC_COMPILER 1
#else
#define PCC_COMPILER 0
#endif
#define TCC_COMPILER (!CL_COMPILER && !CLANG_COMPILER && !GCC_COMPILER && !INTEL_COMPILER && !PCC_COMPILER)

#ifndef max
Expand All @@ -32,4 +37,8 @@
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif

#define MAX_FACTORIAL_64 20
#define MAX_FACTORIAL_128 34
#define PCC_SQRT_ACCURACY 8

#endif
Loading

0 comments on commit 967f01e

Please sign in to comment.