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

Assignments2 #51

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6a40758
Add unit test script
dwalkes Aug 12, 2020
f8ec531
Updates for assignment 2
akshita-bhasin Jun 17, 2020
ad429d6
Add assignment 3 part 1 changes
dwalkes May 21, 2022
93a6e55
Use assignment3 container image
Jan 23, 2022
e0a72ba
Remove full test for assignment 4
Jan 23, 2022
3a5e8e8
Add threading tets for assignment 4
dwalkes May 21, 2022
d58a442
Assignment 5 changes
dwalkes May 22, 2022
0c84502
Changes for assignment 6
dwalkes Jul 2, 2022
bf83b44
Assignment 7 source
dwalkes Aug 13, 2022
7dcb203
Go to assignment 8
dwalkes Aug 14, 2022
4d5ef82
Assignment 8 base implementation
dwalkes Aug 14, 2022
93f0669
Go to assignment 9
dwalkes Aug 14, 2022
2c95858
Add aesd_ioctl.h file for assignment 9
dwalkes Aug 14, 2022
e34c0d0
yaml fix for a2
lnxblog Oct 8, 2022
81484b9
Revert "yaml fix for a2"
lnxblog Oct 8, 2022
3bf587a
yaml changes for a3p1
lnxblog Oct 9, 2022
c5419ed
Revert "yaml changes for a3p1"
lnxblog Oct 9, 2022
21907d9
Update aesd_ioctl.h
dwalkes Oct 31, 2022
74e0e29
Merge branch 'master' into assignment2
dwalkes Jan 15, 2023
667e247
Merge branch 'assignment2' into assignment3-part-1
dwalkes Jan 15, 2023
c93ab2a
Merge branch 'assignment3-part-1' into assignment3-part-2
dwalkes Jan 15, 2023
691b457
Merge branch 'assignment3-part-2' into assignment4
dwalkes Jan 15, 2023
467b20a
Merge branch 'assignment4' into assignment5
dwalkes Jan 15, 2023
8bbf662
Merge branch 'assignment5' into assignment6
dwalkes Jan 15, 2023
3998e8c
Merge branch 'assignment6' into assignment7
dwalkes Feb 11, 2023
775cb4c
Merge branch 'assignment7' into assignment8
dwalkes Feb 11, 2023
a69a4c2
Merge remote-tracking branch 'origin/master' into assignment2
dwalkes Aug 28, 2024
e8431ef
Merge remote-tracking branch 'origin/assignment2' into assignment3-pa…
dwalkes Aug 28, 2024
e96d30e
Merge branch 'assignment3-part-1' into assignment3-part-2
dwalkes Aug 28, 2024
21f5f74
Update linux version to 5.15
dwalkes Aug 28, 2024
e485aee
Merge branch 'assignment3-part-2' into assignment4
dwalkes Aug 28, 2024
dbafafa
Merge branch 'assignment4' into assignment5
dwalkes Aug 28, 2024
347f388
Merge branch 'assignment5' into assignment6
dwalkes Aug 28, 2024
19305ad
Merge branch 'assignment6' into assignment7
dwalkes Aug 28, 2024
a9d1044
Merge branch 'assignment7' into assignment8
dwalkes Aug 28, 2024
db89587
Merge branch 'assignment8' into assignment9
dwalkes Aug 28, 2024
f475446
On branch Assignments2
Nov 3, 2024
b8d6225
On branch Assignments2
Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Run unit test
run: ./unit-test.sh
full-test:
container: cuaesd/aesd-autotest:24-assignment1
container: cuaesd/aesd-autotest:24-assignment7
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ crosstool-ng
aesd-build
.vscode/
test.sh.log
aesdsocket
server/aesdsocket
server/valgrind-out.txt
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ project(aesd-assignments)
# At minimum it should include the files in the test/assignmentX directory
# Students can also add paths to their own test files using a ../ prefix to
# reference this working directory

set(CMAKE_C_FLAGS "-pthread")

set(AUTOTEST_SOURCES
test/assignment1/Test_hello.c
test/assignment1/Test_assignment_validate.c
../student-test/assignment1/Test_validate_username.c
test/assignment7/Test_circular_buffer.c

)
# A list of all files containing test code that is used for assignment validation
set(TESTED_SOURCE
../examples/autotest-validate/autotest-validate.c
../aesd-char-driver/aesd-circular-buffer.c
)
add_subdirectory(assignment-autotest)
9 changes: 9 additions & 0 deletions aesd-char-driver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.order
*.symvers
*.ko
.*.cmd
.tmp_versions*
*.mod.c
linux_source_cdt
*.mod
build
30 changes: 30 additions & 0 deletions aesd-char-driver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See example Makefile from scull project
# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS)

ifneq ($(KERNELRELEASE),)
# call from kernel build system
obj-m := aesdchar.o
aesdchar-y := aesd-circular-buffer.o main.o
else

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

4 changes: 4 additions & 0 deletions aesd-char-driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# AESD Char Driver

Template source code for the AESD char driver used with assignments 8 and later

58 changes: 58 additions & 0 deletions aesd-char-driver/aesd-circular-buffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file aesd-circular-buffer.c
* @brief Functions and data related to a circular buffer imlementation
*
* @author Dan Walkes
* @date 2020-03-01
* @copyright Copyright (c) 2020
*
*/

#ifdef __KERNEL__
#include <linux/string.h>
#else
#include <string.h>
#endif

#include "aesd-circular-buffer.h"

/**
* @param buffer the buffer to search for corresponding offset. Any necessary locking must be performed by caller.
* @param char_offset the position to search for in the buffer list, describing the zero referenced
* character index if all buffer strings were concatenated end to end
* @param entry_offset_byte_rtn is a pointer specifying a location to store the byte of the returned aesd_buffer_entry
* buffptr member corresponding to char_offset. This value is only set when a matching char_offset is found
* in aesd_buffer.
* @return the struct aesd_buffer_entry structure representing the position described by char_offset, or
* NULL if this position is not available in the buffer (not enough data is written).
*/
struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
size_t char_offset, size_t *entry_offset_byte_rtn )
{
/**
* TODO: implement per description
*/
return NULL;
}

/**
* Adds entry @param add_entry to @param buffer in the location specified in buffer->in_offs.
* If the buffer was already full, overwrites the oldest entry and advances buffer->out_offs to the
* new start location.
* Any necessary locking must be handled by the caller
* Any memory referenced in @param add_entry must be allocated by and/or must have a lifetime managed by the caller.
*/
void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry)
{
/**
* TODO: implement per description
*/
}

/**
* Initializes the circular buffer described by @param buffer to an empty struct
*/
void aesd_circular_buffer_init(struct aesd_circular_buffer *buffer)
{
memset(buffer,0,sizeof(struct aesd_circular_buffer));
}
82 changes: 82 additions & 0 deletions aesd-char-driver/aesd-circular-buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* aesd-circular-buffer.h
*
* Created on: March 1st, 2020
* Author: Dan Walkes
*/

#ifndef AESD_CIRCULAR_BUFFER_H
#define AESD_CIRCULAR_BUFFER_H

#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stddef.h> // size_t
#include <stdint.h> // uintx_t
#include <stdbool.h>
#endif

#define AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED 10

struct aesd_buffer_entry
{
/**
* A location where the buffer contents in buffptr are stored
*/
const char *buffptr;
/**
* Number of bytes stored in buffptr
*/
size_t size;
};

struct aesd_circular_buffer
{
/**
* An array of pointers to memory allocated for the most recent write operations
*/
struct aesd_buffer_entry entry[AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED];
/**
* The current location in the entry structure where the next write should
* be stored.
*/
uint8_t in_offs;
/**
* The first location in the entry structure to read from
*/
uint8_t out_offs;
/**
* set to true when the buffer entry structure is full
*/
bool full;
};

extern struct aesd_buffer_entry *aesd_circular_buffer_find_entry_offset_for_fpos(struct aesd_circular_buffer *buffer,
size_t char_offset, size_t *entry_offset_byte_rtn );

extern void aesd_circular_buffer_add_entry(struct aesd_circular_buffer *buffer, const struct aesd_buffer_entry *add_entry);

extern void aesd_circular_buffer_init(struct aesd_circular_buffer *buffer);

/**
* Create a for loop to iterate over each member of the circular buffer.
* Useful when you've allocated memory for circular buffer entries and need to free it
* @param entryptr is a struct aesd_buffer_entry* to set with the current entry
* @param buffer is the struct aesd_buffer * describing the buffer
* @param index is a uint8_t stack allocated value used by this macro for an index
* Example usage:
* uint8_t index;
* struct aesd_circular_buffer buffer;
* struct aesd_buffer_entry *entry;
* AESD_CIRCULAR_BUFFER_FOREACH(entry,&buffer,index) {
* free(entry->buffptr);
* }
*/
#define AESD_CIRCULAR_BUFFER_FOREACH(entryptr,buffer,index) \
for(index=0, entryptr=&((buffer)->entry[index]); \
index<AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED; \
index++, entryptr=&((buffer)->entry[index]))



#endif /* AESD_CIRCULAR_BUFFER_H */
46 changes: 46 additions & 0 deletions aesd-char-driver/aesd_ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* aesd_ioctl.h
*
* Created on: Oct 23, 2019
* Author: Dan Walkes
*
* @brief Definitins for the ioctl used on aesd char devices for assignment 9
*/

#ifndef AESD_IOCTL_H
#define AESD_IOCTL_H

#ifdef __KERNEL__
#include <asm-generic/ioctl.h>
#include <linux/types.h>
#else
#include <sys/ioctl.h>
#include <stdint.h>
#endif

/**
* A structure to be passed by IOCTL from user space to kernel space, describing the type
* of seek performed on the aesdchar driver
*/
struct aesd_seekto {
/**
* The zero referenced write command to seek into
*/
uint32_t write_cmd;
/**
* The zero referenced offset within the write
*/
uint32_t write_cmd_offset;
};

// Pick an arbitrary unused value from https://github.com/torvalds/linux/blob/master/Documentation/userspace-api/ioctl/ioctl-number.rst
#define AESD_IOC_MAGIC 0x16

// Define a write command from the user point of view, use command number 1
#define AESDCHAR_IOCSEEKTO _IOWR(AESD_IOC_MAGIC, 1, struct aesd_seekto)
/**
* The maximum number of commands supported, used for bounds checking
*/
#define AESDCHAR_IOC_MAXNR 1

#endif /* AESD_IOCTL_H */
35 changes: 35 additions & 0 deletions aesd-char-driver/aesdchar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* aesdchar.h
*
* Created on: Oct 23, 2019
* Author: Dan Walkes
*/

#ifndef AESD_CHAR_DRIVER_AESDCHAR_H_
#define AESD_CHAR_DRIVER_AESDCHAR_H_

#define AESD_DEBUG 1 //Remove comment on this line to enable debug

#undef PDEBUG /* undef it, just in case */
#ifdef AESD_DEBUG
# ifdef __KERNEL__
/* This one if debugging is on, and kernel space */
# define PDEBUG(fmt, args...) printk( KERN_DEBUG "aesdchar: " fmt, ## args)
# else
/* This one for user space */
# define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
# endif
#else
# define PDEBUG(fmt, args...) /* not debugging: nothing */
#endif

struct aesd_dev
{
/**
* TODO: Add structure(s) and locks needed to complete assignment requirements
*/
struct cdev cdev; /* Char device structure */
};


#endif /* AESD_CHAR_DRIVER_AESDCHAR_H_ */
25 changes: 25 additions & 0 deletions aesd-char-driver/aesdchar_load
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
module=aesdchar
device=aesdchar
mode="664"
cd `dirname $0`
set -e
# Group: since distributions do it differently, look for wheel or use staff
if grep -q '^staff:' /etc/group; then
group="staff"
else
group="wheel"
fi

if [ -e ${module}.ko ]; then
echo "Loading local built file ${module}.ko"
insmod ./$module.ko $* || exit 1
else
echo "Local file ${module}.ko not found, attempting to modprobe"
modprobe ${module} || exit 1
fi
major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)
rm -f /dev/${device}
mknod /dev/${device} c $major 0
chgrp $group /dev/${device}
chmod $mode /dev/${device}
10 changes: 10 additions & 0 deletions aesd-char-driver/aesdchar_unload
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
module=aesdchar
device=aesdchar
cd `dirname $0`
# invoke rmmod with all arguments we got
rmmod $module || exit 1

# Remove stale nodes

rm -f /dev/${device}
Loading