Merge remote-tracking branch 'HW0_CODE/master'
merge HW0
This commit is contained in:
		
						commit
						a3d945b185
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					bin/
 | 
				
			||||||
 | 
					build/
 | 
				
			||||||
							
								
								
									
										29
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,29 @@
 | 
				
			||||||
 | 
					image: hwrunner:latest
 | 
				
			||||||
 | 
					variables:
 | 
				
			||||||
 | 
					    GIT_SSL_NO_VERIFY: "true"
 | 
				
			||||||
 | 
					    EXEC: hi
 | 
				
			||||||
 | 
					    HW_DIR: hw0
 | 
				
			||||||
 | 
					    CPU_LIMIT: 10
 | 
				
			||||||
 | 
					    FILE_LIMIT: 1000000
 | 
				
			||||||
 | 
					before_script:
 | 
				
			||||||
 | 
					    - make clean all -C ${HW_DIR}
 | 
				
			||||||
 | 
					stages:
 | 
				
			||||||
 | 
					    - build
 | 
				
			||||||
 | 
					    - run
 | 
				
			||||||
 | 
					    - test
 | 
				
			||||||
 | 
					build:
 | 
				
			||||||
 | 
					    stage: build
 | 
				
			||||||
 | 
					    script:
 | 
				
			||||||
 | 
					        - echo "Build done"
 | 
				
			||||||
 | 
					run:
 | 
				
			||||||
 | 
					    stage: run
 | 
				
			||||||
 | 
					    script:
 | 
				
			||||||
 | 
					        - ulimit -t ${CPU_LIMIT}
 | 
				
			||||||
 | 
					        - ulimit -f ${FILE_LIMIT}
 | 
				
			||||||
 | 
					        - cd ${HW_DIR} && bin/${EXEC} -h
 | 
				
			||||||
 | 
					test:
 | 
				
			||||||
 | 
					    stage: test
 | 
				
			||||||
 | 
					    script:
 | 
				
			||||||
 | 
					        - ulimit -t ${CPU_LIMIT}
 | 
				
			||||||
 | 
					        - ulimit -f ${FILE_LIMIT}
 | 
				
			||||||
 | 
					        - cd ${HW_DIR} && bin/${EXEC}_tests -S --verbose=0 --timeout 30
 | 
				
			||||||
							
								
								
									
										47
									
								
								hw0/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								hw0/Makefile
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,47 @@
 | 
				
			||||||
 | 
					CC := gcc
 | 
				
			||||||
 | 
					SRCD := src
 | 
				
			||||||
 | 
					TSTD := tests
 | 
				
			||||||
 | 
					BLDD := build
 | 
				
			||||||
 | 
					BIND := bin
 | 
				
			||||||
 | 
					INCD := include
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ALL_SRCF := $(shell find $(SRCD) -type f -name *.c)
 | 
				
			||||||
 | 
					ALL_OBJF := $(patsubst $(SRCD)/%,$(BLDD)/%,$(ALL_SRCF:.c=.o))
 | 
				
			||||||
 | 
					FUNC_FILES := $(filter-out build/main.o, $(ALL_OBJF))
 | 
				
			||||||
 | 
					TEST_SRC := $(shell find $(TSTD) -type f -name *.c)
 | 
				
			||||||
 | 
					INC := -I $(INCD)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXEC := hi
 | 
				
			||||||
 | 
					TEST_EXEC := $(EXEC)_tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CFLAGS := -Wall -Werror
 | 
				
			||||||
 | 
					DFLAGS := -g -DDEBUG
 | 
				
			||||||
 | 
					STD := -std=gnu11
 | 
				
			||||||
 | 
					TEST_LIB := -lcriterion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LIBS := -lreadline -pthread -ljansson
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CFLAGS += $(STD)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: clean all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					debug: CFLAGS += -g -DDEBUG
 | 
				
			||||||
 | 
					debug: all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					all: setup $(EXEC) $(TEST_EXEC)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					setup:
 | 
				
			||||||
 | 
						mkdir -p bin build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(EXEC): $(ALL_OBJF)
 | 
				
			||||||
 | 
						$(CC) $^ -o $(BIND)/$@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(TEST_EXEC): $(ALL_OBJF)
 | 
				
			||||||
 | 
						$(CC) $(CFLAGS) $(INC) $(FUNC_FILES) $(TEST_SRC) $(TEST_LIB) -o $(BIND)/$@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(BLDD)/%.o: $(SRCD)/%.c
 | 
				
			||||||
 | 
						$(CC) $(CFLAGS) $(INC) -c -o $@ $<
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						$(RM) -r $(BLDD) $(BIND)
 | 
				
			||||||
							
								
								
									
										0
									
								
								hw0/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								hw0/README.md
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										37
									
								
								hw0/academic_honesty.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								hw0/academic_honesty.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,37 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ACADEMIC HONESTY STATEMENT
 | 
				
			||||||
 | 
					================================================================================
 | 
				
			||||||
 | 
					I certify the following:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1. All files hosted in this repository at any time, including any written
 | 
				
			||||||
 | 
					material and code, are entirely of my own work. The only exception permitted to
 | 
				
			||||||
 | 
					this rule is if the Professor(s) give explicit, written permission, in the
 | 
				
			||||||
 | 
					assignment handout, on the webpage/PIAZZA, or in E-mail, to use or adapt other
 | 
				
			||||||
 | 
					source code into my work. In this case, the origins of all such code is clearly
 | 
				
			||||||
 | 
					cited in my files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. I have not shared, transmitted, or received source code written for this
 | 
				
			||||||
 | 
					class (including in any semester) from anyone else except the Professor(s) and
 | 
				
			||||||
 | 
					the TAs. This includes both electronic forms (E-mail or downloading), as well as
 | 
				
			||||||
 | 
					written or printed source code.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					3. Except in the case of explicit written permission given by the Professor(s),
 | 
				
			||||||
 | 
					I have not included in my repository any source code obtained from a textbook,
 | 
				
			||||||
 | 
					downloaded from the Internet, extracted from a software package or source code
 | 
				
			||||||
 | 
					library, or from any other similar source.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I understand that the appearance of extremely similar code fragments in more
 | 
				
			||||||
 | 
					than one homework submission will be treated as evidence that code has been
 | 
				
			||||||
 | 
					shared and an academic dishonesty case will be filed against me.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I understand that code fragments can be extremely similar even if they are
 | 
				
			||||||
 | 
					formatted differently and use different identifiers/labels/variables. The
 | 
				
			||||||
 | 
					appearance of extremely similar code fragments that differ in this way will be
 | 
				
			||||||
 | 
					regarded as evidence of an attempt to conceal that sharing has taken place.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					When in doubt about whether or not I am permitted to use particular source
 | 
				
			||||||
 | 
					materials, I will obtain written permission from the Professor(s), in advance of
 | 
				
			||||||
 | 
					my submission. Such permission is best requested and obtained by E-mail to
 | 
				
			||||||
 | 
					cse320@cs.stonybrook.edu
 | 
				
			||||||
 | 
					================================================================================
 | 
				
			||||||
 | 
					Signed:
 | 
				
			||||||
							
								
								
									
										46
									
								
								hw0/hw0.sublime-project
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								hw0/hw0.sublime-project
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,46 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    "folders":
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "path":".",
 | 
				
			||||||
 | 
					            "name":"Project Base"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "path": "src",
 | 
				
			||||||
 | 
					            "name": "C Source",
 | 
				
			||||||
 | 
					            "follow_symlinks": false,
 | 
				
			||||||
 | 
					            "file_include_patterns":["*.c"],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "path": "include",
 | 
				
			||||||
 | 
					            "name": "C Headers",
 | 
				
			||||||
 | 
					            "follow_symlinks": false,
 | 
				
			||||||
 | 
					            "file_include_patterns":["*.h"],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "path": "tests",
 | 
				
			||||||
 | 
					            "name": "Tests",
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "settings":
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "build_systems":
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Release (full build)",
 | 
				
			||||||
 | 
					            "working_dir":"$project_path",
 | 
				
			||||||
 | 
					            "shell_cmd": "make clean all",
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Debug (full build)",
 | 
				
			||||||
 | 
					            "working_dir":"$project_path",
 | 
				
			||||||
 | 
					            "shell_cmd": "make clean debug",
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": "Test",
 | 
				
			||||||
 | 
					            "working_dir":"$project_path",
 | 
				
			||||||
 | 
					            "shell_cmd": "bin/${project_base_name}_tests}",
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										14
									
								
								hw0/include/hi.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								hw0/include/hi.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					#ifndef HI_H /* This is a preprocessor macro, it asks the preprocessor if HI_H \
 | 
				
			||||||
 | 
					                is NOT defined */
 | 
				
			||||||
 | 
					#define HI_H /* Since it is not defined we define it */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* We do this to prevent cyclical inclusion */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdio.h> /* This is a C library, this is equivalent to import in java */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char* say_hi(); /* This is a function prototype it defines the return type,
 | 
				
			||||||
 | 
					                   name, and arguments */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* HI_H - This is just the end of the if statement */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Journey on over to `src/main.c` for the next comments. */
 | 
				
			||||||
							
								
								
									
										11
									
								
								hw0/src/hi.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								hw0/src/hi.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					#include "hi.h" /* This is our headerfile */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Here's the actual definition of our say_hi() function
 | 
				
			||||||
 | 
					 * as you can see it simply returns the string "Hi" Or does it??
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char* say_hi(){
 | 
				
			||||||
 | 
					    return "Hello";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/* Back over to main to finish our program */
 | 
				
			||||||
							
								
								
									
										42
									
								
								hw0/src/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								hw0/src/main.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,42 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "hi.h" /* This is our headerfile, containing the definition for say_hi() */
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This is the full definition of a main function in C the beginning of our
 | 
				
			||||||
 | 
					 * program
 | 
				
			||||||
 | 
					 * it is the equivalent of public static void main in java
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * In C main always returns an int, it represents the exit status of your
 | 
				
			||||||
 | 
					 * program
 | 
				
			||||||
 | 
					 * a program that runs successfully returns 0 one that has an error returns any
 | 
				
			||||||
 | 
					 * positive value
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The arguments passed to main are as follows:
 | 
				
			||||||
 | 
					 * - int argc: this is the size of the argv array
 | 
				
			||||||
 | 
					 * - char const *argv[] is an array of strings that are the command line
 | 
				
			||||||
 | 
					 *   arguments for the program
 | 
				
			||||||
 | 
					 * - char const *envp[] are the environment variables availible to any program
 | 
				
			||||||
 | 
					 *   run in the OS's environment
 | 
				
			||||||
 | 
					 * You can define main to have any of these arguments removed `int main()` for
 | 
				
			||||||
 | 
					 * example is entirely valid.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void* noop(void* v){return NULL;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char const *argv[], char const *envp[]) {
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					     * say_hi() is a function that returns a character pointer (a.k.a a string)
 | 
				
			||||||
 | 
					     * Journey on over to `src/hi.c` for the next comments.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    char *hello = say_hi();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					     * This is a print statement in C it places the arguments
 | 
				
			||||||
 | 
					     * following the format string into a string following the
 | 
				
			||||||
 | 
					     * format string's design.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    printf("%s, %s%c\n", hello, "World", '!');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* End of our program */
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/* Head over to tests/test.c to see what a unit test looks like */
 | 
				
			||||||
							
								
								
									
										16
									
								
								hw0/tests/test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								hw0/tests/test.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					#include <criterion/criterion.h>
 | 
				
			||||||
 | 
					#include "hi.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This is Criterion, an excellent testing framework for C.
 | 
				
			||||||
 | 
					 * It is also really well documented.
 | 
				
			||||||
 | 
					 * http://criterion.readthedocs.io/en/master/starter.html
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					Test(CSE320_Suite, test_it_really_does_say_hi) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cr_assert_str_not_empty(say_hi(),
 | 
				
			||||||
 | 
					                            "say_hi() function returns empty string!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cr_assert_str_eq(say_hi(), "Hi",
 | 
				
			||||||
 | 
					                     "say_hi() function did not say 'Hi'");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user